Skip to main content

slingshot_postgres 0.1.7 copy "slingshot_postgres: ^0.1.7" to clipboard
slingshot_postgres: ^0.1.7 copied to clipboard

PostgreSQL driver for Dart backends over libpq and dart:ffi: a native thread-per-connection pool, async I/O that never blocks an isolate, zero-copy result reads.

example/main.dart

/// First-contact example for `slingshot_postgres`.
///
/// Opens a pool, runs a couple of queries inside a transaction, and
/// closes everything cleanly. Other files in this directory drill into
/// specific patterns (raw queries, repositories, pipelined writes,
/// diagnostics).
///
/// Run (with Postgres up at localhost:5432, dbname=teste):
///   dart run example/main.dart
library;

import 'package:slingshot_postgres/slingshot_postgres.dart';

const _connInfo =
    'host=localhost port=5432 dbname=teste user=postgres password=123';

Future<void> main() async {
  final pool = PostgresConnectionPool(
    const PoolConfig(connInfo: _connInfo, maxSize: 4),
  );
  await pool.start();

  try {
    final greeting = await withTransaction<String>(pool, (exec) async {
      final rs = await exec.execute("SELECT 'hello from libpq' AS msg");
      try {
        return rs.row(0).getString('msg')!;
      } finally {
        rs.release();
      }
    });
    print(greeting);
  } finally {
    await pool.close();
  }
}
1
likes
0
points
1.46k
downloads

Publisher

unverified uploader

Weekly Downloads

PostgreSQL driver for Dart backends over libpq and dart:ffi: a native thread-per-connection pool, async I/O that never blocks an isolate, zero-copy result reads.

Repository (GitHub)
View/report issues

Topics

#database #postgres #postgresql #ffi

License

unknown (license)

Dependencies

ffi, meta, slingshot

More

Packages that depend on slingshot_postgres