sqlite-android implements the support interfaces directly starting with version 3.21.0
which means this wrapper is no longer needed. You can migrate by removing this dependency and
changing imports of com.gabrielittner.sqlite.RequerySQLiteOpenHelperFactory
to
io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory
.
A wrapper around Requery's sqlite-android library
that implements SupportSQLite
interfaces from the support library. This allows you to ship your
own version of SQLite and use it with a shared platform independent API.
The only public class in this library is RequerySQLiteOpenHelperFactory
which creates and returns
an implementation of SupportSQLiteOpenHelper
.
Instead of extending SQLiteOpenHelper
you have to extend SupportSQLiteOpenHelper.Callback
:
class DbCallback extends SupportSQLiteOpenHelper.Callback {
public DbCallback(int version) {
super(version);
}
@Override
public void onCreate(SupportSQLiteDatabase db) {
// create db
}
@Override
public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
// upgrade db
}
}
Use that to create an instance of SupportSQLiteOpenHelper.Configuration
and pass it to the factory:
SupportSQLiteOpenHelper.Configuration config = SupportSQLiteOpenHelper.Configuration.builder(context)
.name("database-name.db")
.callback(new DbCallback())
.build();
SupportSQLiteOpenHelper helper = new RequerySQLiteOpenHelperFactory().create(config);
// use helper as usual
To use this with Room just pass an instance of RequerySQLiteOpenHelperFactory
to it's database
builder:
Room.databaseBuilder(context, YourDatabase.class, "database-name")
.openHelperFactory(new RequerySQLiteOpenHelperFactory())
.build();
Using this library requires version 3.0.0
of SQL Brite. Create the SupportSQLiteOpenHelper
as described in
regular usage and pass it into wrapDatabaseHelper
:
SupportSQLiteOpenHelper helper = ... // see above
BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
Currently not supported, keep an eye on: cashapp/sqldelight#566
Add a Gradle dependency:
compile 'com.gabrielittner.sqlite:support-db-requery:0.2.0'
Snapshots of the development version are available in Sonatype's snapshots
repository.
Copyright (C) 2016 The Android Open Source Project
Copyright 2017 Gabriel Ittner
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.