powersync_sqlcipher 0.1.1 copy "powersync_sqlcipher: ^0.1.1" to clipboard
powersync_sqlcipher: ^0.1.1 copied to clipboard

PowerSync Flutter SDK - sync engine for building local-first apps.

example/main.dart

import 'package:flutter/foundation.dart';
import 'package:powersync_sqlcipher/powersync.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart';

const schema = Schema([
  Table('customers', [Column.text('name'), Column.text('email')])
]);

late PowerSyncDatabase db;

// Setup connector to backend if you would like to sync data.
class BackendConnector extends PowerSyncBackendConnector {
  PowerSyncDatabase db;

  BackendConnector(this.db);
  @override
  // ignore: body_might_complete_normally_nullable
  Future<PowerSyncCredentials?> fetchCredentials() async {
    // implement fetchCredentials
  }
  @override
  Future<void> uploadData(PowerSyncDatabase database) async {
    // implement uploadData
  }
}

openDatabase() async {
  var path = 'powersync-demo.db';
  // getApplicationSupportDirectory is not supported on Web
  if (!kIsWeb) {
    final dir = await getApplicationSupportDirectory();
    path = join(dir.path, 'powersync-dart.db');
  }

  // Setup the database.
  final cipherFactory = PowerSyncSQLCipherOpenFactory(
      path: path, key: "sqlcipher-encryption-key");

  db = PowerSyncDatabase.withFactory(cipherFactory, schema: schema);

  await db.initialize();

  // Run local statements.
  await db.execute(
      'INSERT INTO customers(id, name, email) VALUES(uuid(), ?, ?)',
      ['Fred', 'fred@example.org']);

  // Connect to backend
  db.connect(connector: BackendConnector(db));
}
0
likes
160
points
154
downloads

Publisher

verified publisherpowersync.com

Weekly Downloads

PowerSync Flutter SDK - sync engine for building local-first apps.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter, powersync_core, powersync_flutter_libs, sqlcipher_flutter_libs

More

Packages that depend on powersync_sqlcipher