powersync 1.0.0
powersync: ^1.0.0 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;
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']);
}
connectPowerSync() async {
// DevConnector stores credentials in-memory by default.
// Extend the class to persist credentials.
final connector = DevConnector();
// Login in dev mode.
await connector.devLogin(
endpoint: 'https://myinstance.powersync.co',
user: 'demo',
password: 'demo');
// Connect to PowerSync service and start sync.
db.connect(connector: connector);
}