From 4973815d592aef4399d64437f30730ba2af1b8d1 Mon Sep 17 00:00:00 2001 From: danylo-safonov-solid Date: Thu, 21 Sep 2023 19:00:42 +0300 Subject: [PATCH] upd --- lib/src/connection.dart | 49 ++++++++++++++++++++++++++++++++++++++++- lib/src/pool.dart | 2 ++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/src/connection.dart b/lib/src/connection.dart index b026934..55242f5 100644 --- a/lib/src/connection.dart +++ b/lib/src/connection.dart @@ -1 +1,48 @@ -class Connection {} +import 'dart:js_interop'; +import 'dart:js_util'; + +import 'package:deno_postgres_interop/src/client_configuration.dart'; +import 'package:deno_postgres_interop/src/promise.dart'; +import 'package:deno_postgres_interop/src/transport.dart'; +import 'package:deno_postgres_interop/src/util.dart'; + +/// [deno-postgres@v0.17.0/Connection](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection). +@JS() +class Connection { + /// [deno-postgres@v0.17.0/Connection/connected](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#accessor_pid). + external int get pid; + + /// [deno-postgres@v0.17.0/Connection/constructor](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#ctor_0). + factory Connection({ + required ClientConfiguration connectionParams, + required Future Function() disconnectionCallback, + }) => + callConstructor( + 'Connection', + [connectionParams, () => futureToPromise(disconnectionCallback())], + ); +} + +/// [deno-postgres@v0.17.0/Connection](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection). +extension ConnectionProps on Connection { + /// [deno-postgres@v0.17.0/Connection/connected](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#prop_connected). + bool get isConnected => getProperty(this, 'connected'); + + /// [deno-postgres@v0.17.0/Connection/tls](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#accessor_tls). + bool get isCarriedOverTLS => getProperty(this, 'tls'); + + /// [deno-postgres@v0.17.0/Connection/transport](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#accessor_transport). + Transport get transport => Transport.parse(getProperty(this, 'transport')); + + /// [deno-postgres@v0.17.0/Connection/end](https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#method_end_0). + Future end() => callFutureMethod(this, 'end'); + + // https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#method_query_0 + // query(query: Query): Promise + + // https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#method_query_1 + // query(query: Query): Promise + + // https://deno.land/x/postgres@v0.17.0/connection/connection.ts?s=Connection#method_startup_0 + // startup(is_reconnection: boolean) +} diff --git a/lib/src/pool.dart b/lib/src/pool.dart index 5669484..7309075 100644 --- a/lib/src/pool.dart +++ b/lib/src/pool.dart @@ -1,3 +1,4 @@ +import 'dart:js_interop'; import 'dart:js_util'; import 'package:deno_postgres_interop/src/client_options.dart'; @@ -6,6 +7,7 @@ import 'package:deno_postgres_interop/src/undefined.dart'; import 'package:deno_postgres_interop/src/util.dart'; /// [deno-postgres@v0.17.0/Pool](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Pool). +@JS() class Pool { /// [deno-postgres@v0.17.0/Pool/constructor](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Pool#ctor_0). factory Pool({