Search in sources :

Example 1 with AndroidSqliteDriver

use of app.cash.sqldelight.driver.android.AndroidSqliteDriver in project sqldelight by square.

the class IntegrationTests method before.

@Before
public void before() {
    database = new AndroidSqliteDriver(QueryWrapper.Companion.getSchema(), InstrumentationRegistry.getContext());
    queryWrapper = QueryWrapper.Companion.invoke(database);
    personQueries = queryWrapper.getPersonQueries();
    keywordsQueries = queryWrapper.getSqliteKeywordsQueries();
}
Also used : AndroidSqliteDriver(app.cash.sqldelight.driver.android.AndroidSqliteDriver) Before(org.junit.Before)

Example 2 with AndroidSqliteDriver

use of app.cash.sqldelight.driver.android.AndroidSqliteDriver in project sqldelight by square.

the class MigrationTest method testMigrationWorks.

@Test
public void testMigrationWorks() throws IOException {
    // Set up version 1 db.
    SupportSQLiteOpenHelper.Callback callback = new SupportSQLiteOpenHelper.Callback(1) {

        @Override
        public void onCreate(SupportSQLiteDatabase db) {
            db.execSQL("CREATE TABLE person (\n" + "  _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" + "  first_name TEXT NOT NULL\n" + ");");
            db.execSQL("CREATE TABLE `group` (\n" + "  _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" + "  'where' INTEGER NOT NULL,\n" + "  [having] INTEGER NOT NULL\n" + ");");
            db.execSQL("INSERT INTO person VALUES (1, 'alec');");
        }

        @Override
        public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
        }
    };
    SupportSQLiteOpenHelper.Configuration configuration = SupportSQLiteOpenHelper.Configuration.builder(InstrumentationRegistry.getTargetContext()).callback(callback).name("test.db").build();
    SupportSQLiteOpenHelper helper = new FrameworkSQLiteOpenHelperFactory().create(configuration);
    // Creates the db.
    helper.getWritableDatabase().execSQL("DELETE FROM person WHERE first_name NOT IN ('alec')");
    helper.close();
    // Migrate the db with a queryWrapper
    SqlDriver database = new AndroidSqliteDriver(QueryWrapper.Companion.getSchema(), InstrumentationRegistry.getTargetContext(), "test.db");
    QueryWrapper queryWrapper = QueryWrapper.Companion.invoke(database);
    // Assert info is correct
    Person person = queryWrapper.getPersonQueries().nameIn(Arrays.asList("alec")).executeAsOne();
    assertThat(person).isEqualTo(new Person(1, "alec", "sup"));
    database.close();
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) FrameworkSQLiteOpenHelperFactory(androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory) SqlDriver(app.cash.sqldelight.db.SqlDriver) AndroidSqliteDriver(app.cash.sqldelight.driver.android.AndroidSqliteDriver) SupportSQLiteOpenHelper(androidx.sqlite.db.SupportSQLiteOpenHelper) Test(org.junit.Test)

Aggregations

AndroidSqliteDriver (app.cash.sqldelight.driver.android.AndroidSqliteDriver)2 SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)1 SupportSQLiteOpenHelper (androidx.sqlite.db.SupportSQLiteOpenHelper)1 FrameworkSQLiteOpenHelperFactory (androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory)1 SqlDriver (app.cash.sqldelight.db.SqlDriver)1 Before (org.junit.Before)1 Test (org.junit.Test)1