This file contains 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
import android.app.Application | |
import com.fsryan.forsuredb.FSDBHelper | |
import com.fsryan.forsuredb.ForSureAndroidInfoFactory | |
import com.fsryan.forsuredb.gsonserialization.FSDbInfoGsonSerializer | |
import com.fsryan.forsuredb.api.FSTableCreator | |
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() |
This file contains 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
package com.fsryan.example.forsuredb.data.db.tables; | |
import com.fsryan.forsuredb.annotations.FSColumn; | |
import com.fsryan.forsuredb.annotations.FSTable; | |
import com.fsryan.forsuredb.annotations.Unique; | |
import com.fsryan.forsuredb.api.FSGetApi; | |
import com.fsryan.forsuredb.api.Retriever; | |
@FSTable("employees") | |
public interface EmployeesTable extends FSGetApi { |
This file contains 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
w: Note: [DiffGenerator] analyzing diff: targetContext.allTables().size() = 1 | |
w: Note: [MigrationGenerator] Number of migrations in set = 4 | |
w: Note: [ResourceCreator] creating resource at location: CLASS_OUTPUT | |
w: Note: [MigrationGenerator] creating source file: /path/to/app/build/tmp/kapt3/classes/debug/com/fsryan/example/forsuredb/1526923325850.migration | |
> Task :app:dbMigrate | |
I/[forsuredbplugin.dbMigrate]: creating /path/to/app/src/main/assets to store migration files | |
I/[forsuredbplugin.dbMigrate]: copying migration file /path/to/app/build/tmp/kapt3/classes/debug/com/fsryan/example/forsuredb/1526923325850.migration to /path/to/app/src/main/assets/1526923325850.migration.json |
This file contains 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
// java version | |
String uuid1 = UUID.randomUUID().toString(); | |
// the below assumes use of forsuredbandroid-contentprovider | |
// as the platform integration library. SaveResult would be | |
// parameterized with DirectLocator if using | |
// forsuredbandroid-directdb or forsuredbjdbc | |
SaveResult<Uri> saveResult = ForSure.employeesTable() | |
.set() | |
.firstName("FS") |
This file contains 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
// java version | |
EmployeesTable api = ForSure.employeesTable().getApi(); | |
Retriever retriever = ForSure.employeesTable.get(); | |
if (retriever.moveToFirst()) { | |
do { // log employee record fields using generated api | |
String msg = "Employee{uuid=" + api.uuid(retriever); | |
msg += "; first_name=" + api.firstName(retriever); | |
msg += "; last_name=" + api.lastName(retriever); | |
msg += "; _id=" + api.id(retriever); |
This file contains 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
// java version | |
// supposing there is at least one record with first_name="FS" | |
// and last_name="Ryan", this code will perform an update to | |
// all matching records. Otherwise, it will insert. This is | |
// called "upsert." | |
// the below assumes use of forsuredbandroid-contentprovider | |
// as the platform integration library. SaveResult would be | |
// parameterized with DirectLocator if using | |
// forsuredbandroid-directdb or forsuredbjdbc |
This file contains 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
// java version | |
int deleted = ForSure.employeesTable() | |
.find().byFirstName("Some") | |
.then() | |
.set() | |
.hardDelete(); | |
Log.i("forsuredb-example", "Deleted " + deleted + " records") |
This file contains 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
// java version | |
// the below assumes use of forsuredbandroid-contentprovider | |
// as the platform integration library. SaveResult would be | |
// parameterized with DirectLocator if using | |
// forsuredbandroid-directdb or forsuredbjdbc | |
SaveResult<Uri> saveResult = ForSure.employeesTable() | |
.find().byFirstName("Some") | |
.then() | |
.set() |
This file contains 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
I/forsuredb-example( 1832): SaveResult{exception: null; inserted: content://com.fsryan.example.forsuredb.content/employees/1; rowsAffected: 1} | |
I/forsuredb-example( 1832): SaveResult{exception: null; inserted: content://com.fsryan.example.forsuredb.content/employees/2; rowsAffected: 1} | |
I/forsuredb-example( 1832): Employee{uuid=c00399eb-7ac2-4d34-8d5e-2bc01846413d; firstName=FS; lastName=Ryan; _id=1; created=Tue May 22 17:29:50 EDT 2018; deleted=false; modified Tue May 22 17:29:50 EDT 2018} | |
I/forsuredb-example( 1832): SaveResult{exception: null; inserted: null; rowsAffected: 1} | |
I/forsuredb-example( 1832): Employee{uuid=c00399eb-7ac2-4d34-8d5e-2bc01846413d; firstName=First; lastName=Last; _id=1; created=Tue May 22 17:29:50 EDT 2018; deleted=false; modified Tue May 22 17:29:50 EDT 2018} | |
I/forsuredb-example( 1832): Employee{uuid=3746ee35-2212-43cf-9009-1b9bfb6a07b8; firstName=Some; lastName=Employee; _id=2; created=Tue May 22 17:29:50 EDT 2018; deleted=false; modified Tue May 22 17:29:50 EDT 2018} | |
I/forsuredb-exam |
This file contains 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
val uuid = UUID.randomUUID().toString() | |
// create (upsert) | |
ForSure.employeesTable() | |
.set().firstName("Some").lastName("Name").uuid(uuid) | |
.save() | |
//retrieve | |
val api = ForSure.employeesTable().api | |
val retriever = ForSure.employeesTable().get() | |
if (retriever.moveToFirst()) { |