-
Notifications
You must be signed in to change notification settings - Fork 10
Saving
For saving SqliteMagic generates the following builder methods on @Table
annotated classes:
-
insert()
Builder for inserting object into database usingINSERT
SQLite statement. Execution methods produce saved row primary key.-
conflictAlgorithm(@ConflictAlgorithm int)
Builder method for defining a conflict algorithm for operation. -
usingConnection(DbConnection)
Define which database connection to use for executing this operation. Whithout defining it SqliteMagic uses the default connection.
-
-
insert(Iterable<T>)
Static builder for inserting multiple objects into database inside a transaction usingINSERT
SQLite statement. Execution methods produceboolean
result indicating the success of the operation.-
usingConnection(DbConnection)
Define which database connection to use for executing this operation. Whithout defining it SqliteMagic uses the default connection.
-
-
persist()
Builder for persisting object into database using eitherINSERT
SQLite statement, if there is no row with the object's primary key orUPDATE
SQLite statement, if object can be updated. Execution methods produce persisted row primary key.-
ignoreNullValues()
Configure this operation to ignorenull
column values when persisting provided object. -
usingConnection(DbConnection)
Define which database connection to use for executing this operation. Whithout defining it SqliteMagic uses the default connection.
-
-
persist(Iterable<T>)
Static builder for persisting multiple objects into database inside a transaction using eitherINSERT
SQLite statement, if there is no row with persistable object's primary key orUPDATE
SQLite statement, if object can be updated. Execution methods produceboolean
result indicating the success of the operation.- Builder options same as
persist()
.
- Builder options same as
Important! Generated methods are starting points to building database operations. Each builder contains several operation options and must end with an "executive" method - either execute()
for synchronous execution or observe()
for starting point into reactive world.
Example:
Synchronous | RxJava |
---|---|
Author author = new Author(
73, "Foo", "Bar");
Book book = new Book(
77, "Bar", author);
// insert -- NOTE: author
// object also gets
// inserted and the whole
// operation is wrapped
// in transaction
long id = book
.insert()
.execute();
// update or insert
id = author
.persist()
.execute();
// update or insert, but
// ignore null values
id = author
.persist()
.ignoreNullValues()
.execute();
// Bulk operations
boolean success = Author
.persist(someAuthors)
.ignoreNullValues()
.execute(); |
Author author = new Author(
73, "Foo", "Bar");
Book book = new Book(
77, "Bar", author);
// insert -- NOTE: author
// object also gets
// inserted and the whole
// operation is wrapped
// in transaction when result
// object gets subscribed
Single<Long> insert = book
.insert()
.observe();
// update or insert
Single<Long> persist = author
.persist()
.observe();
// update or insert, but
// ignore null values
persist = author
.persist()
.ignoreNullValues()
.observe();
// Bulk operations
Completable bulkPersist = Author
.persist(someAuthors)
.ignoreNullValues()
.observe(); |