Skip to content

Latest commit

 

History

History
143 lines (104 loc) · 3.66 KB

File metadata and controls

143 lines (104 loc) · 3.66 KB

Installation

Download the appropriate pre-built binary for your platform from the official Releases page:

  • Linux: x86 and ARM
  • macOS: x86 and ARM
  • Windows: x86
  • Android
  • iOS

SQLite CLI / C

-- In SQLite CLI
.load ./cloudsync

-- In SQL
SELECT load_extension('./cloudsync');

Swift Package

Add this repository as a package dependency to your Swift project. After adding the package, set up SQLite with extension loading by following steps 4 and 5 of this guide.

import CloudSync

var db: OpaquePointer?
sqlite3_open(":memory:", &db)
sqlite3_enable_load_extension(db, 1)
var errMsg: UnsafeMutablePointer<Int8>? = nil
sqlite3_load_extension(db, CloudSync.path, nil, &errMsg)
var stmt: OpaquePointer?
sqlite3_prepare_v2(db, "SELECT cloudsync_version()", -1, &stmt, nil)
defer { sqlite3_finalize(stmt) }
sqlite3_step(stmt)
log("cloudsync_version(): \(String(cString: sqlite3_column_text(stmt, 0)))")
sqlite3_close(db)

Android

Add the following to your Gradle dependencies:

implementation 'ai.sqlite:sync:1.0.0'
SQLiteCustomExtension cloudsyncExtension = new SQLiteCustomExtension(
    getApplicationInfo().nativeLibraryDir + "/cloudsync", null);
SQLiteDatabaseConfiguration config = new SQLiteDatabaseConfiguration(
    getCacheDir().getPath() + "/cloudsync_test.db",
    SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.OPEN_READWRITE,
    Collections.emptyList(),
    Collections.emptyList(),
    Collections.singletonList(cloudsyncExtension)
);
SQLiteDatabase db = SQLiteDatabase.openDatabase(config, null, null);

For full implementation details, see the complete Android example.

Expo

Install the Expo package:

npm install @sqliteai/sqlite-sync-expo

Add to your app.json:

{
  "expo": {
    "plugins": ["@sqliteai/sqlite-sync-expo"]
  }
}

Run prebuild:

npx expo prebuild --clean

Load the extension:

import { Platform } from 'react-native';
import { getDylibPath, open } from '@op-engineering/op-sqlite';

const db = open({ name: 'mydb.db' });

// Load SQLite Sync extension
if (Platform.OS === 'ios') {
  const path = getDylibPath('ai.sqlite.cloudsync', 'CloudSync');
  db.loadExtension(path);
} else {
  db.loadExtension('cloudsync');
}

React Native

Install the React Native library:

npm install @sqliteai/sqlite-sync-react-native

Then follow the instructions from the README.

Flutter

Add the sqlite_sync package to your project:

flutter pub add sqlite_sync  # Flutter projects
dart pub add sqlite_sync     # Dart projects
import 'package:sqlite3/sqlite3.dart';
import 'package:sqlite_sync/sqlite_sync.dart';

sqlite3.loadSqliteSyncExtension();
final db = sqlite3.openInMemory();
print(db.select('SELECT cloudsync_version()'));

For a complete example, see the Flutter example.

WASM

The WebAssembly version of SQLite with the SQLite Sync extension is available on npm:

npm install @sqliteai/sqlite-wasm

See the npm package for usage details.