diff --git a/README.md b/README.md index 839f899..8a36e94 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,8 @@ Insert vectors ```dart await connection.execute( - "INSERT INTO items (embedding) VALUES (@a), (@b), (@c)", - substitutionValues: { + Sql.named("INSERT INTO items (embedding) VALUES (@a), (@b), (@c)"), + parameters: { "a": pgvector.encode([1, 1, 1]), "b": pgvector.encode([2, 2, 2]), "c": pgvector.encode([1, 1, 2]) @@ -53,14 +53,14 @@ await connection.execute( Get the nearest neighbors ```dart -List> results = await connection.query( - "SELECT id, embedding FROM items ORDER BY embedding <-> @embedding LIMIT 5", - substitutionValues: { +List> results = await connection.execute( + Sql.named("SELECT id, embedding FROM items ORDER BY embedding <-> @embedding LIMIT 5"), + parameters: { "embedding": pgvector.encode([1, 1, 1]) }); for (final row in results) { print(row[0]); - print(pgvector.decode(row[1])); + print(pgvector.decode(row[1].bytes)); } ``` diff --git a/pubspec.yaml b/pubspec.yaml index 380f7b9..a8b62ee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,5 +10,5 @@ dependencies: dev_dependencies: lints: ^2.0.0 - postgres: ^2.6.2 + postgres: ^3.0.0 test: ^1.21.0 diff --git a/test/postgres_test.dart b/test/postgres_test.dart index a9e2722..76dace2 100644 --- a/test/postgres_test.dart +++ b/test/postgres_test.dart @@ -5,10 +5,13 @@ import 'package:test/test.dart'; void main() { test('works', () async { - var connection = PostgreSQLConnection( - "localhost", 5432, "pgvector_dart_test", - username: Platform.environment["USER"]); - await connection.open(); + var connection = await Connection.open( + Endpoint( + host: "localhost", + port: 5432, + database: "pgvector_dart_test", + username: Platform.environment["USER"]), + settings: ConnectionSettings(sslMode: SslMode.disable)); await connection.execute("CREATE EXTENSION IF NOT EXISTS vector"); await connection.execute("DROP TABLE IF EXISTS items"); @@ -17,21 +20,22 @@ void main() { "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3))"); await connection.execute( - "INSERT INTO items (embedding) VALUES (@a), (@b), (@c)", - substitutionValues: { + Sql.named("INSERT INTO items (embedding) VALUES (@a), (@b), (@c)"), + parameters: { "a": pgvector.encode([1, 1, 1]), "b": pgvector.encode([2, 2, 2]), "c": pgvector.encode([1, 1, 2]) }); - List> results = await connection.query( - "SELECT id, embedding FROM items ORDER BY embedding <-> @embedding LIMIT 5", - substitutionValues: { + List> results = await connection.execute( + Sql.named( + "SELECT id, embedding FROM items ORDER BY embedding <-> @embedding LIMIT 5"), + parameters: { "embedding": pgvector.encode([1, 1, 1]) }); for (final row in results) { print(row[0]); - print(pgvector.decode(row[1])); + print(pgvector.decode(row[1].bytes)); } await connection