Skip to content

Instantly share code, notes, and snippets.

View ryansgot's full-sized avatar

Ryan ryansgot

  • Fukuoka, Japan
  • 00:57 (UTC +09:00)
View GitHub Profile
@ryansgot
ryansgot / basic_create_query.java
Last active December 27, 2017 08:21
Basic Forsuredb Create (insert) query android
SaveResult<Uri> result = Forsuredb.myTable() // <-- the generated ForSure class serves as your entrypoint
.set() // <-- enter insert/update/delete portion of query
.stringColumn("My String") // <-- set the value of the column
.intColumn(42) // <-- column value setters are typesafe
.save(); // <-- performs the insertion and sends back a SaveResult
Uri inserted = result.inserted(); // <-- SaveResult contains a locator for the inserted record
@ryansgot
ryansgot / basic_forsuredb_retrieval_query.java
Last active December 27, 2017 08:32
Basic Forsuredb Retrieval Query
MyTable myTableApi = ForSure.myTable().getApi(); // <-- get retrieval API that Forsuredb generated for you
Retriever r = ForSure.myTable() // <-- the generated ForSure class serves as your entrypoint
.find() // <-- start narrowing the number of records and columns to return
.byIntColumnBetween(3).andInclusive(10) // <-- set bounds (3, 10]
.and().byNotDeleted() // <-- add additional condition that the record must not be "soft deleted"
.then() // <-- end narrowing number of records and columns to return
.get(); // <-- execute the query and return a Retriever (a Cursor/ResultSet)
if (r.moveToFirst()) { // <-- Retrievers get iterated just like Cursors or ResultSets
do {
String stringColumn = myTableApi.stringColumn(r);
@ryansgot
ryansgot / basic_forsuredb_upsert_query_android.java
Last active December 27, 2017 08:31
Basic Forsuredb Upsert Query (android)
SaveResult<Uri> result = ForSure.myTable()
.find() // <-- start narrowing the number of records and columns to update
.byIntColumnBetween(3).andInclusive(10) // <-- set bounds (3, 10]
.and().byNotDeleted() // <-- add additional condition that the record must not be "soft deleted"
.then() // <-- end narrowing number of records and columns to return
.set() // <-- start setting column values to update
.stringColumn("Your int_column value is greater than three and less than or equal to 10")
.save();
System.out.println("Number of records updated: " + result.rowsAffected());
@ryansgot
ryansgot / basic_forsuredb_delete_query.java
Last active December 27, 2017 08:32
Basic Forsuredb Delete Query
int rowsAffected = ForSure.myTable() // <-- the generated ForSure class serves as your entrypoint
.find() // <-- start narrowing the number of records and columns to update
.byIntColumnBetween(3).andInclusive(10) // <-- set bounds (3, 10]
.and().byNotDeleted() // <-- add additional condition that the record must not be "soft deleted"
.then() // <-- end narrowing number of records and columns to return
.set() // <-- enter insert/update/delete section
.hardDelete(); // <-- perform a hard deletion--actually deleting the record
System.out.println("Number of records deleted: " + rowsAffected);
@ryansgot
ryansgot / forsuredb-android-directdb-config.gradle
Created May 10, 2018 00:26
forsuredb-android-directdb-config
forsuredb {
applicationPackageName = 'com.fsryan.forsuredb.example'
resultParameter = "com.fsryan.forsuredb.queryable.DirectLocator"
recordContainer = "com.fsryan.forsuredb.queryable.FSContentValues"
migrationDirectory = 'app/src/main/assets'
appProjectDirectory = 'app'
resourcesDirectory = 'app/src/main/resources'
fsSerializerFactoryClass = 'com.fsryan.forsuredb.example.JsonAdapterFactory'
dbmsIntegratorClass = 'com.fsryan.forsuredb.sqlitelib.SqlGenerator'
}
@ryansgot
ryansgot / dbmigrate task gist
Last active May 21, 2018 17:11
forsuredb dbmigrate task
$ ./gradlew :app:dbMigrate
@ryansgot
ryansgot / adding-forsuredb-compiler-dependency-android.gradle
Last active May 10, 2018 21:23
Adding the forsuredbcompiler dependency
// Android
dependencies {
/* ... */
annotationProcessor "com.fsryan.forsuredb:forsuredbcompiler:$forsuredbversion"
/* ... */
}
@ryansgot
ryansgot / adding-forsuredbplugin-to-your-project-app.grade
Created May 10, 2018 21:33
Adding forsuredbplugin to your project
apply plugin: /*'com.android.application', 'com.android.library', or 'java'*/
apply plugin: 'com.fsryan.gradle.forsuredb'
forsuredb {
/*...*/
}
@ryansgot
ryansgot / EmployeesTable.java
Last active May 21, 2018 14:07
Example Forsure DB Table Definition
package com.fsryan.forsuredb.example.data.db;
import com.fsryan.forsuredb.annotations.FSColumn;
import com.fsryan.forsuredb.annotations.FSDefault;
import com.fsryan.forsuredb.annotations.FSForeignKey;
import com.fsryan.forsuredb.annotations.FSTable;
import com.fsryan.forsuredb.annotations.Unique;
import com.fsryan.forsuredb.api.FSGetApi;
import com.fsryan.forsuredb.api.Retriever;
@ryansgot
ryansgot / example-forsuredb-retrieval-query.java
Created May 10, 2018 22:08
Example Forsure DB retrieval query
Retriever r = ForSure.employeesTable()
.find().byNotDeleted()
.and().byFirstName("FSRyan")
.and().byLastName("Developer")
.then()
.get();