synclayer_postgres 1.0.0
synclayer_postgres: ^1.0.0 copied to clipboard
PostgreSQL adapter for SyncLayer - enables offline-first sync with PostgreSQL database.
synclayer_postgres #
PostgreSQL adapter for SyncLayer - enables offline-first synchronization with PostgreSQL database.
Installation #
dependencies:
synclayer: ^1.4.1
synclayer_postgres: ^1.0.0
Usage #
import 'package:synclayer/synclayer.dart';
import 'package:synclayer_postgres/synclayer_postgres.dart';
import 'package:postgres/postgres.dart';
final connection = await Connection.open(
Endpoint(
host: 'localhost',
database: 'mydb',
username: 'user',
password: 'password',
),
);
await SyncLayer.init(
SyncConfig(
customBackendAdapter: PostgresAdapter(connection: connection),
collections: ['todos'],
),
);
Database Schema #
CREATE TABLE todos (
record_id VARCHAR(255) PRIMARY KEY,
data JSONB NOT NULL,
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
version INTEGER NOT NULL DEFAULT 1
);
CREATE INDEX idx_updated_at ON todos(updated_at);
License #
MIT License