Deleting entities

alt text alt text alt text

You have two ways to delete entities in KittyORM:

Closer look on SQLiteConditionBuilder.class

SQLiteConditionBuilder.class is a builder for generating WHERE clauses within KittyORM. It is really simple to use and it is designed to generate WHERE clauses in most natural for SQLite way: just add column names, SQLite operators and values for your clause in an order they should appear in SQLite clause. For example, clause WHERE a_column = 'a' AND (b_column > 0 OR BETWEEN 10 AND 20) would be generated by following code:

 1SQLiteCondition condition = new SQLiteConditionBuilder()
 2            .addColumn("a_column")
 3            .addSQLOperator(EQUAL)
 4            .addValue("a")
 5            .addSQLOperator(AND)
 6            .addSQLOperator(OPEN_SUBC)
 7            .addColumn("b_column")
 8            .addSQLOperator(GREATER_THAN)
 9            .addValue(0)
10            .addSQLOperator(OR)
11            .addSQLOperator(BETWEEN)
12            .addValue(10)
13            .addSQLOperator(AND)
14            .addValue(20)
15            .addSQLOperator(CLOSE_SUBC)
16            .build();
17
18// Note that following condition is equal to previous one
19SQLiteCondition condition2 = new SQLiteConditionBuilder()
20            .addColumn("a_column")
21            .addSQLOperator("=")
22            .addValue("a")
23            .addSQLOperator("AND")
24            .addSQLOperator("(")
25            .addColumn("b_column")
26            .addSQLOperator(">=")
27            .addValue(0)
28            .addSQLOperator("OR")
29            .addSQLOperator("BETWEEN")
30            .addValue(10)
31            .addSQLOperator("AND")
32            .addValue(20)
33            .addSQLOperator(")")
34            .build();
35
36// And, finally, you can pass to condition builder not only column names but POJO field names as well
37SQLiteCondition condition3 = new SQLiteConditionBuilder()
38            .addField("aColumn", SomeModel.class)
39            .addSQLOperator("=")
40            .addValue("a")
41            .addSQLOperator("AND")
42            .addSQLOperator("(")
43            .addField("bColumn", SomeModel.class)
44            .addSQLOperator(">=")
45            .addValue(0)
46            .addSQLOperator("OR")
47            .addSQLOperator("BETWEEN")
48            .addValue(10)
49            .addSQLOperator("AND")
50            .addValue(20)
51            .addSQLOperator(")")
52            .build();
53
54// Also, if you would like use SQLite string to build condition, you may use following method:
55SQLiteCondition condition4 = SQLiteConditionBuilder.fromSQL("WHERE a_column = ? AND (b_column > ? OR BETWEEN ? AND ?)", SomeModel.class, "a", 0, 10, 20);
56
57// And, for SQLite string, you may pass POJO field names as well using #?fieldName syntax
58SQLiteCondition condition5 = SQLiteConditionBuilder.fromSQL("WHERE #?aColumn = ? AND (#?bColumn > ? OR BETWEEN ? AND ?)", SomeModel.class, "a", 0, 10, 20);
All supported by KittyORM SQLite operators presented at net.akaish.kitty.orm.query.conditions.SQLiteOperator enumeration.