toxicity-io / sqlite-mc

An SQLDelight driver that uses SQLite3MultipleCiphers for database encryption.
Apache License 2.0
13 stars 0 forks source link

sqlite-mc

badge-license badge-latest-release

badge-kotlin badge-sqlite badge-coroutines badge-encoding badge-immutable badge-sqldelight badge-sqlitemc badge-sqliter badge-sqlitejdbc

badge-platform-android badge-platform-jvm badge-platform-ios badge-platform-tvos badge-platform-watchos badge-support-apple-silicon

An SQLDelight driver that uses SQLite3MultipleCiphers for database encryption.

Usage

Jvm Supported Operating Systems

NOTE: macOS and Windows binaries are code signed.

x86 x86_64 armv5 armv6 armv7 arm64 ppc64
Windows
macOS
Linux (libc)
Linux (musl)
FreeBSD

Library Versioning

Versioning follows the following pattern of SQLDelight - SQLite3MultipleCiphers - sqlite-mc sub version

SQLite3MultipleCiphers Flags

SQLite3MultipleCiphers is compiled with the following flags

Jvm & Native:

SQLITE_HAVE_ISNAN=1
HAVE_USLEEP=1
SQLITE_ENABLE_COLUMN_METADATA=1
SQLITE_CORE=1
SQLITE_ENABLE_FTS3=1
SQLITE_ENABLE_FTS3_PARENTHESIS=1
SQLITE_ENABLE_FTS5=1
SQLITE_ENABLE_RTREE=1
SQLITE_ENABLE_STAT4=1
SQLITE_ENABLE_DBSTAT_VTAB=1
SQLITE_ENABLE_MATH_FUNCTIONS=1
SQLITE_DEFAULT_MEMSTATUS=0
SQLITE_DEFAULT_FILE_PERMISSIONS=0666
SQLITE_MAX_VARIABLE_NUMBER=250000
SQLITE_MAX_MMAP_SIZE=0
SQLITE_MAX_LENGTH=2147483647
SQLITE_MAX_COLUMN=32767
SQLITE_MAX_SQL_LENGTH=1073741824
SQLITE_MAX_FUNCTION_ARG=127
SQLITE_MAX_ATTACHED=125
SQLITE_MAX_PAGE_COUNT=4294967294
SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
SQLITE_DQS=0
CODEC_TYPE=CODEC_TYPE_CHACHA20
SQLITE_ENABLE_EXTFUNC=1
SQLITE_ENABLE_REGEXP=1
SQLITE_TEMP_STORE=2
SQLITE_USE_URI=1

Jvm

SQLITE_THREADSAFE=1

Native:

SQLITE_THREADSAFE=2
SQLITE_OMIT_LOAD_EXTENSION

Reason ``` 2 (Multi-Threaded) is the default for Darwin targets, but on JVM it is using 1 (Serialized). SQLDelight's NativeSqliteDriver utilizes thread pools and nerfs any benefit that Serialized would offer, so. This *might* change in the future if migrating away from SQLDelight's NativeSqliteDriver and SQLiter. Omission of the load extension code is only able to be set for Native, as Jvm requires the code to remain in order to link with the JNI interface. Extension loading is disabled by default for Jvm, but the C code must stay in order to mitigate modifying the Java codebase. ```

Darwin:

SQLITE_ENABLE_API_ARMOR
SQLITE_OMIT_AUTORESET

Reason ``` Options that SQLite is compiled with on Darwin devices. macOS 10.11.6+, iOS 9.3.5+ ```

iOS, tvOS, watchOS:

SQLITE_ENABLE_LOCKING_STYLE=0

Reason ``` D.Richard Hipp (SQLite architect) suggests for non-macOS: "The SQLITE_ENABLE_LOCKING_STYLE thing is an apple-only extension that boosts performance when SQLite is used on a network filesystem. This is important on macOS because some users think it is a good idea to put their home directory on a network filesystem. I'm guessing this is not really a factor on iOS." ```

Get Started

  1. Remove SQLDelight gradle plugin and driver dependencies from your project
  2. Apply the sqlite-mc gradle plugin.

    plugins {
       // Provides the SQLDelight gradle plugin automatically and applies it
       id("io.toxicity.sqlite-mc") version("2.0.2-1.9.0-0")
    }
    
    // Will automatically:
    //  - Configure the latest SQLite dialect
    //  - Add the sqlite-mc driver dependency
    //  - Link native targets for provided SQLite3MultipleCiphers binaries
    sqliteMC {
       databases {
           // Configure just like you would the SQLDelight plugin
       }
    }
  3. If you have Android unit tests
    dependencies {
       // For android unit tests (NOT instrumented)
       //
       // This is simply the desktop binary resources needed for
       // JDBC to operate locally on the machine.
       testImplementation("io.toxicity.sqlite-mc:android-unit-test:2.0.2-1.9.0-0")
    }