powersync 1.2.1 copy "powersync: ^1.2.1" to clipboard
powersync: ^1.2.1 copied to clipboard

PowerSync Flutter SDK - keep PostgreSQL databases in sync with on-device SQLite databases.

PowerSync SDK for Dart/Flutter #

PowerSync is a service and set of SDKs that keeps PostgreSQL databases in sync with on-device SQLite databases.

SDK Features #

  • Real-time streaming of changes.
  • Direct access to the SQLite database - use SQL on the client and server.
  • Operations are asynchronous by default - does not block the UI.
  • Supports one write and many reads concurrently.
  • No need for client-side database migrations - these are handled automatically.
  • Subscribe to queries for live updates.

Getting started #

import 'package:powersync/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
  Future<PowerSyncCredentials?> fetchCredentials() async {
    // implement fetchCredentials
  }
  @override
  Future<void> uploadData(PowerSyncDatabase database) async {
    // implement uploadData
  }
}

openDatabase() async {
  final dir = await getApplicationSupportDirectory();
  final path = join(dir.path, 'powersync-dart.db');
  // Setup the database.
  db = PowerSyncDatabase(schema: schema, path: path);
  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));
}
47
likes
0
pub points
88%
popularity

Publisher

verified publisherpowersync.com

PowerSync Flutter SDK - keep PostgreSQL databases in sync with on-device SQLite databases.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

async, collection, flutter, http, logging, sqlite3_flutter_libs, sqlite_async, uuid

More

Packages that depend on powersync