Skip to content

Commit 9a75f04

Browse files
QueryClient & Transaction (#7)
* wip * fix * rm commented-out code * extract to file * add comments * docs * fix * upd * test * upd * flutter_version * test * ? * blessrng * blessRNG * experiment * up * ultra bless * . * maybe closer * not bruh * please * <> * 777 * pls * ultra please * pls * hope * fix * fix * versions * fix * init? * done? * fix * upd * part * add placeholders * exports * fixes * fixes * more fixes * source * todo * clientOptions * info * remove things that are implemented * simplify checklist * align * extract checklist * more implemented * upd * upd * Savepoint * fix comments * promise docs * savepoint comments * ClientOptions comments * hosttype * partialconnectionoptions upd * partialTLSOptions * uncomment * progress * partially resolve queryObject * upd * upd * big upd * fix * split by files * init * CommandType * notice * ResultType * working type * placeholders * working * more consistent comments * rowdescription * query * split by files * queryObjectOptions * uint8 * init * mini upd * working * remove generic * upd * init * upd * init * rm duplicate * restore * restore order * part * more prope * upd * fix * todos * upd * constructor * parse * todo * upd * upd * fix comments * upd * upd * upd * constructor * upd * upd * export * tls options * finish? * upd * last * upd * upd * upd * revert * revert * upd * upd * fix * restore * add comments * comments * update unimplemented * upd * upd * upd * upd * transaction * fin * upd * impl * seemps good * upd * exports
1 parent 3cb0548 commit 9a75f04

File tree

10 files changed

+269
-22
lines changed

10 files changed

+269
-22
lines changed

lib/deno_postgres_interop.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,26 @@ library;
44
export 'src/client.dart';
55
export 'src/client_configuration.dart';
66
export 'src/client_options.dart';
7+
export 'src/column.dart';
78
export 'src/command_type.dart';
9+
export 'src/connection.dart';
810
export 'src/connection_options.dart';
11+
export 'src/encoded_arg.dart';
912
export 'src/isolation_level.dart';
13+
export 'src/notice.dart';
1014
export 'src/partial/partial_connection_options.dart';
1115
export 'src/partial/partial_tls_options.dart';
1216
export 'src/pool.dart';
1317
export 'src/pool_client.dart';
1418
export 'src/query.dart';
19+
export 'src/query_array_result.dart';
1520
export 'src/query_client.dart';
1621
export 'src/query_object_result.dart';
1722
export 'src/query_result.dart';
23+
export 'src/result_type.dart';
24+
export 'src/row_description.dart';
25+
export 'src/savepoint.dart';
26+
export 'src/session.dart';
1827
export 'src/tls_options.dart';
1928
export 'src/transaction.dart';
2029
export 'src/transaction_options.dart';

lib/src/client.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import 'dart:js_interop';
2+
import 'dart:js_util';
23

4+
import 'package:deno_postgres_interop/src/client_options.dart';
35
import 'package:deno_postgres_interop/src/query_client.dart';
46

57
/// [[email protected]/Client](https://deno.land/x/[email protected]/mod.ts?s=Client).
68
@JS()
79
class Client extends QueryClient {
810
/// [[email protected]/Client/constructor](https://deno.land/x/[email protected]/mod.ts?s=Client#ctor_0).
911
external factory Client(String dbUrl);
12+
13+
/// [[email protected]/Client/constructor](https://deno.land/x/[email protected]/mod.ts?s=Client#ctor_0).
14+
factory Client.config(ClientOptions config) =>
15+
callConstructor('Client', [config]);
16+
17+
/// [[email protected]/Client/constructor](https://deno.land/x/[email protected]/mod.ts?s=Client#ctor_0).
18+
factory Client.empty() => callConstructor('Client', null);
1019
}

lib/src/connection.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'dart:js_interop';
2+
import 'dart:js_util';
3+
4+
import 'package:deno_postgres_interop/src/client_configuration.dart';
5+
import 'package:deno_postgres_interop/src/promise.dart';
6+
import 'package:deno_postgres_interop/src/query.dart';
7+
import 'package:deno_postgres_interop/src/query_result.dart';
8+
import 'package:deno_postgres_interop/src/transport.dart';
9+
import 'package:deno_postgres_interop/src/util.dart';
10+
11+
/// [[email protected]/Connection](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection).
12+
@JS()
13+
class Connection {
14+
/// [[email protected]/Connection/connected](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#accessor_pid).
15+
external int get pid;
16+
17+
/// [[email protected]/Connection/constructor](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#ctor_0).
18+
factory Connection({
19+
required ClientConfiguration connectionParams,
20+
required Future<void> Function() disconnectionCallback,
21+
}) =>
22+
callConstructor(
23+
'Connection',
24+
[connectionParams, () => futureToPromise(disconnectionCallback())],
25+
);
26+
}
27+
28+
/// [[email protected]/Connection](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection).
29+
extension ConnectionProps on Connection {
30+
/// [[email protected]/Connection/connected](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#prop_connected).
31+
bool get isConnected => getProperty(this, 'connected');
32+
33+
/// [[email protected]/Connection/tls](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#accessor_tls).
34+
bool get isCarriedOverTLS => getProperty(this, 'tls');
35+
36+
/// [[email protected]/Connection/transport](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#accessor_transport).
37+
Transport get transport => Transport.parse(getProperty(this, 'transport'));
38+
39+
/// [[email protected]/Connection/end](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#method_end_0).
40+
Future<void> end() => callFutureMethod(this, 'end');
41+
42+
/// [[email protected]/Connection/query](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#method_query_0).
43+
/// [[email protected]/Connection/query](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#method_query_1).
44+
Future<T> queryArray<T extends QueryResult>(Query query) =>
45+
callFutureMethod(this, 'query', [query]);
46+
47+
/// [[email protected]/Connection/startup](https://deno.land/x/[email protected]/connection/connection.ts?s=Connection#method_startup_0).
48+
Future<void> startup({required bool isReconnection}) =>
49+
callFutureMethod(this, 'startup', [isReconnection]);
50+
}

lib/src/notice.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
import 'dart:js_interop';
22
import 'dart:js_util';
33

4-
/// [[email protected]/Notice](https://deno.land/x/[email protected]/connection/message.ts?s=Notice).
4+
/// [deno-[email protected]/Notice](https://deno.land/x/[email protected]/connection/message.ts?s=Notice).
55
@JS()
66
class Notice {
7-
/// [[email protected]/Notice/severity](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_severity).
7+
/// [deno-[email protected]/Notice/severity](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_severity).
88
external String get severity;
99

10-
/// [[email protected]/Notice/code](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_code).
10+
/// [deno-[email protected]/Notice/code](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_code).
1111
external String get code;
1212

13-
/// [[email protected]/Notice/message](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_message).
13+
/// [deno-[email protected]/Notice/message](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_message).
1414
external String get message;
1515

16-
/// [[email protected]/Notice/detail](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_detail).
16+
/// [deno-[email protected]/Notice/detail](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_detail).
1717
external String? get detail;
1818

19-
/// [[email protected]/Notice/hint](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_hint).
19+
/// [deno-[email protected]/Notice/hint](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_hint).
2020
external String? get hint;
2121

22-
/// [[email protected]/Notice/position](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_position).
22+
/// [deno-[email protected]/Notice/position](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_position).
2323
external String? get position;
2424

25-
/// [[email protected]/Notice/internalPosition](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_internalPosition).
25+
/// [deno-[email protected]/Notice/internalPosition](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_internalPosition).
2626
external String? get internalPosition;
2727

28-
/// [[email protected]/Notice/internalQuery](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_internalQuery).
28+
/// [deno-[email protected]/Notice/internalQuery](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_internalQuery).
2929
external String? get internalQuery;
3030

31-
/// [[email protected]/Notice/where](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_where).
31+
/// [deno-[email protected]/Notice/where](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_where).
3232
external String? get where;
3333

34-
/// [[email protected]/Notice/schema](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_schema).
34+
/// [deno-[email protected]/Notice/schema](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_schema).
3535
external String? get schema;
3636

37-
/// [[email protected]/Notice/table](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_table).
37+
/// [deno-[email protected]/Notice/table](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_table).
3838
external String? get table;
3939

40-
/// [[email protected]/Notice/column](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_column).
40+
/// [deno-[email protected]/Notice/column](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_column).
4141
external String? get column;
4242

43-
/// [[email protected]/Notice/dataType](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_dataType).
43+
/// [deno-[email protected]/Notice/dataType](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_dataType).
4444
external String? get dataType;
4545

46-
/// [[email protected]/Notice/constraint](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_constraint).
46+
/// [deno-[email protected]/Notice/constraint](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_constraint).
4747
external String? get constraint;
4848

49-
/// [[email protected]/Notice/file](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_file).
49+
/// [deno-[email protected]/Notice/file](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_file).
5050
external String? get file;
5151

52-
/// [[email protected]/Notice/line](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_line).
52+
/// [deno-[email protected]/Notice/line](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_line).
5353
external String? get line;
5454

55-
/// [[email protected]/Notice/routine](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_routine).
55+
/// [deno-[email protected]/Notice/routine](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_routine).
5656
external String? get routine;
5757

58-
/// [[email protected]/Notice](https://deno.land/x/[email protected]/connection/message.ts?s=Notice).
58+
/// [deno-[email protected]/Notice](https://deno.land/x/[email protected]/connection/message.ts?s=Notice).
5959
factory Notice({
6060
required String severity,
6161
required String code,

lib/src/pool.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:js_interop';
12
import 'dart:js_util';
23

34
import 'package:deno_postgres_interop/src/client_options.dart';
@@ -6,6 +7,7 @@ import 'package:deno_postgres_interop/src/undefined.dart';
67
import 'package:deno_postgres_interop/src/util.dart';
78

89
/// [[email protected]/Pool](https://deno.land/x/[email protected]/mod.ts?s=Pool).
10+
@JS()
911
class Pool {
1012
/// [[email protected]/Pool/constructor](https://deno.land/x/[email protected]/mod.ts?s=Pool#ctor_0).
1113
factory Pool({

lib/src/promise.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:js_interop';
2+
import 'dart:js_util';
3+
4+
typedef _Resolver<T> = void Function(T result);
5+
typedef _Executor<T> = void Function(_Resolver<T> resolve, Function reject);
6+
7+
/// JS [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) interop.
8+
@JS()
9+
class Promise<T> {
10+
/// [js/Promise/constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/Promise).
11+
external Promise(_Executor<T> executor);
12+
}
13+
14+
/// Convert darts [Future] to js' [Promise].
15+
Promise<T> futureToPromise<T>(Future<T> future) {
16+
return Promise<T>(
17+
allowInterop((resolve, reject) {
18+
future.then(resolve, onError: reject);
19+
}),
20+
);
21+
}

lib/src/query_client.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,36 @@ import 'dart:js_interop';
22
import 'dart:js_util';
33

44
import 'package:deno_postgres_interop/src/client_common.dart';
5+
import 'package:deno_postgres_interop/src/connection.dart';
56
import 'package:deno_postgres_interop/src/query_array_result.dart';
67
import 'package:deno_postgres_interop/src/query_object_options.dart';
78
import 'package:deno_postgres_interop/src/query_object_result.dart';
9+
import 'package:deno_postgres_interop/src/session.dart';
810
import 'package:deno_postgres_interop/src/transaction.dart';
911
import 'package:deno_postgres_interop/src/transaction_options.dart';
1012
import 'package:deno_postgres_interop/src/util.dart';
1113

1214
/// [[email protected]/QueryClient](https://deno.land/x/[email protected]/mod.ts?s=QueryClient).
1315
@JS()
14-
class QueryClient {}
16+
class QueryClient {
17+
/// [[email protected]/QueryClient/session](https://deno.land/x/[email protected]/mod.ts?s=QueryClient#accessor_session).
18+
external Session get session;
19+
20+
/// [[email protected]/QueryClient/constructor](https://deno.land/x/[email protected]/mod.ts?s=QueryClient#ctor_0).
21+
external factory QueryClient(Connection connection);
22+
}
1523

1624
/// [[email protected]/QueryClient](https://deno.land/x/[email protected]/mod.ts?s=QueryClient).
1725
extension QueryClientProps on QueryClient {
26+
/// [[email protected]/QueryClient/connected](https://deno.land/x/[email protected]/mod.ts?s=QueryClient#accessor_connected).
27+
bool get isConnected => getProperty(this, 'connected');
28+
29+
/// [[email protected]/QueryClient/closeConnection](https://deno.land/x/[email protected]/mod.ts?s=QueryClient#method_closeConnection_0).
30+
Future<void> closeConnection() => callFutureMethod(this, 'closeConnection');
31+
32+
/// [[email protected]/QueryClient/resetSessionMetadata](https://deno.land/x/[email protected]/mod.ts?s=QueryClient#method_resetSessionMetadata_0).
33+
void resetSessionMetadata() => callMethod(this, 'resetSessionMetadata', []);
34+
1835
/// [[email protected]/QueryClient/connect](https://deno.land/x/[email protected]/mod.ts?s=QueryClient#method_connect_0).
1936
Future<void> connect() => callFutureMethod(this, 'connect');
2037

lib/src/savepoint.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import 'dart:js_interop';
2+
import 'dart:js_util';
3+
4+
import 'package:deno_postgres_interop/src/promise.dart';
5+
import 'package:deno_postgres_interop/src/util.dart';
6+
7+
/// [[email protected]/Savepoint](https://deno.land/x/[email protected]/mod.ts?s=Savepoint).
8+
@JS()
9+
class Savepoint {
10+
/// [[email protected]/Savepoint/constructor](https://deno.land/x/[email protected]/mod.ts?s=Savepoint#ctor_0).
11+
factory Savepoint(
12+
String name,
13+
Future<void> Function(String name) updateCallback,
14+
Future<void> Function(String name) releaseCallback,
15+
) =>
16+
callConstructor('Savepoint', [
17+
name,
18+
(String name) => futureToPromise(updateCallback(name)),
19+
(String name) => futureToPromise(releaseCallback(name)),
20+
]);
21+
}
22+
23+
/// [[email protected]/Savepoint](https://deno.land/x/[email protected]/mod.ts?s=Savepoint).
24+
extension SavepointProps on Savepoint {
25+
/// [[email protected]/Savepoint/instances](https://deno.land/x/[email protected]/mod.ts?s=Savepoint#accessor_instances).
26+
int get instancesCount => getProperty(this, 'instances');
27+
28+
/// [[email protected]/Savepoint/instances](https://deno.land/x/[email protected]/mod.ts?s=Savepoint#method_release_0).
29+
Future<void> release() => callFutureMethod(this, 'release');
30+
31+
/// [[email protected]/Savepoint/instances](https://deno.land/x/[email protected]/mod.ts?s=Savepoint#method_update_0).
32+
Future<void> update() => callFutureMethod(this, 'update');
33+
}

lib/src/session.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'dart:js_interop';
2+
import 'dart:js_util';
3+
4+
import 'package:deno_postgres_interop/src/transport.dart';
5+
6+
/// [[email protected]/Session](https://deno.land/x/[email protected]/mod.ts?s=Session).
7+
@JS()
8+
class Session {
9+
/// [[email protected]/Session/pid](https://deno.land/x/[email protected]/mod.ts?s=Session#prop_pid)
10+
external int? get pid;
11+
12+
/// [[email protected]/Session/tls](https://deno.land/x/[email protected]/mod.ts?s=Session#prop_tls)
13+
external bool? get tls;
14+
}
15+
16+
/// [[email protected]/Session](https://deno.land/x/[email protected]/mod.ts?s=Session).
17+
extension SessionProps on Session {
18+
/// [[email protected]/Session/current_transaction](https://deno.land/x/[email protected]/mod.ts?s=Session#prop_current_transaction)
19+
String? get currentTransacton => getProperty(this, 'current_transaction');
20+
21+
/// [[email protected]/Session/transport](https://deno.land/x/[email protected]/mod.ts?s=Session#prop_transport)
22+
Transport? get transport {
23+
final string = getProperty<String?>(this, 'transport');
24+
25+
return string == null ? null : Transport.parse(string);
26+
}
27+
}

0 commit comments

Comments
 (0)