This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static final String CREATE_CATEGORIES_TABLE = "create table " + Category.TABLE + "(" + | |
| COLUMN_ID + " integer primary key autoincrement, " + | |
| Category.COL_NAME + " text, " + | |
| Category.COL_COLOR + " integer, " + | |
| Category.COL_CREATE_BY_USER + " integer DEFAULT 0 " + | |
| ");"; | |
| static String LIST_QUERY(String selection) { | |
| String query = "SELECT *, COUNT(i." + ListItem.COL_STATUS + ") " + List.COL_SIZE | |
| + ", SUM(i." + ListItem.COL_STATUS + ") " + List.COL_BOUGHT_COUNT + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SqlBrite sqlBrite = new SqlBrite.Builder() | |
| .logger(message -> Log.d("Database", message)) // Optional | |
| .queryTransformer(queryTransformer) // Optional | |
| .build(); | |
| SQLiteOpenHelper openHelper = new DBHelper(context); | |
| BriteDatabase db = sqlBrite.wrapDatabaseHelper(openHelper, Schedulers.io()); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<SqlBrite.Query> users = db.createQuery("users", "SELECT * FROM users"); | |
| users.subscribe(new Action1<SqlBrite.Query>() { | |
| @Override public void call(SqlBrite.Query query) { | |
| Cursor cursor = query.run(); | |
| // map data... | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.createQuery("users", "SELECT * FROM users") | |
| .mapToList(Users.MAPPER) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BriteDatabase.Transaction transaction = db.newTransaction(); | |
| try { | |
| db.insert("users", createUser("Mkhytar Mkhoian")); | |
| db.insert("users", createUser("Artem Dudinskyi")); | |
| db.insert("users", createUser("Andrii Rakhimov")); | |
| transaction.markSuccessful(); | |
| } finally { | |
| transaction.end(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BriteContentResolver resolver = sqlBrite.wrapContentProvider(contentResolver, Schedulers.io()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.insert("users", createUser("Mkhytar Mkhoian")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private QueryObservable createQuery(Func1<Set<String>, Boolean> tableFilter, String sql, String... args) { | |
| if(this.transactions.get() != null) { | |
| throw new IllegalStateException("Cannot create observable query in transaction. Use query() for a query inside a transaction."); | |
| } else { | |
| BriteDatabase.DatabaseQuery query = new BriteDatabase.DatabaseQuery(tableFilter, sql, args); | |
| final Observable queryObservable = this.triggers | |
| .filter(tableFilter) // Only trigger on tables we care about. | |
| .map(query) // DatabaseQuery maps to itself to save an allocation. | |
| .onBackpressureLatest() // Guard against uncontrollable frequency of upstream emissions. | |
| .startWith(query) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void sendTableTrigger(Set<String> tables) { | |
| BriteDatabase.SqliteTransaction transaction = (BriteDatabase.SqliteTransaction)this.transactions.get(); | |
| if(transaction != null) { | |
| transaction.addAll(tables); | |
| } else { | |
| if(this.logging) { | |
| this.log("TRIGGER %s", new Object[]{tables}); | |
| } | |
| this.triggers.onNext(tables); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| buildscript { | |
| repositories { | |
| mavenCentral() | |
| } | |
| dependencies { | |
| classpath 'com.squareup.sqldelight:gradle-plugin:0.6.1' | |
| } | |
| } | |
| apply plugin: 'com.squareup.sqldelight' |
OlderNewer