Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientCommon #10

Merged
merged 72 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
14d1469
partially resolve queryObject
danylo-safonov-solid Sep 15, 2023
0f0a0c5
upd
danylo-safonov-solid Sep 18, 2023
4fbcdf4
upd
danylo-safonov-solid Sep 18, 2023
abaf4c6
big upd
danylo-safonov-solid Sep 18, 2023
f59ef27
fix
danylo-safonov-solid Sep 18, 2023
c206335
split by files
danylo-safonov-solid Sep 18, 2023
d15417e
init
danylo-safonov-solid Sep 18, 2023
db75396
CommandType
danylo-safonov-solid Sep 18, 2023
737d5fb
notice
danylo-safonov-solid Sep 18, 2023
c1f6a1d
ResultType
danylo-safonov-solid Sep 18, 2023
91f9831
working type
danylo-safonov-solid Sep 18, 2023
da3208f
placeholders
danylo-safonov-solid Sep 18, 2023
d3f8d90
working
danylo-safonov-solid Sep 18, 2023
c92dd81
more consistent comments
danylo-safonov-solid Sep 18, 2023
eefbfd2
sync
danylo-safonov-solid Sep 18, 2023
efae6a2
sync
danylo-safonov-solid Sep 18, 2023
13750a9
rowdescription
danylo-safonov-solid Sep 18, 2023
fd0274e
query
danylo-safonov-solid Sep 18, 2023
330b1fa
split by files
danylo-safonov-solid Sep 18, 2023
53ffeba
queryObjectOptions
danylo-safonov-solid Sep 18, 2023
2be332b
uint8
danylo-safonov-solid Sep 18, 2023
6ebfab9
init
danylo-safonov-solid Sep 18, 2023
20e5d3f
mini upd
danylo-safonov-solid Sep 18, 2023
8f965ff
working
danylo-safonov-solid Sep 18, 2023
8075339
remove generic
danylo-safonov-solid Sep 18, 2023
3f8c731
sync
danylo-safonov-solid Sep 18, 2023
16dd4b5
sync
danylo-safonov-solid Sep 19, 2023
99010b3
upd
danylo-safonov-solid Sep 19, 2023
ee30c72
init
danylo-safonov-solid Sep 19, 2023
9000f58
upd
danylo-safonov-solid Sep 19, 2023
2c06285
sync
danylo-safonov-solid Sep 19, 2023
3252e45
init
danylo-safonov-solid Sep 19, 2023
0168f8d
sync
danylo-safonov-solid Sep 19, 2023
3ff9819
rm duplicate
danylo-safonov-solid Sep 19, 2023
69f0268
restore
danylo-safonov-solid Sep 19, 2023
7c2474a
restore order
danylo-safonov-solid Sep 19, 2023
b1652e1
sync
danylo-safonov-solid Sep 19, 2023
03714ff
sync
danylo-safonov-solid Sep 19, 2023
5516b9f
part
danylo-safonov-solid Sep 19, 2023
38540f1
more prope
danylo-safonov-solid Sep 19, 2023
b0391f1
upd
danylo-safonov-solid Sep 19, 2023
747a4b8
fix
danylo-safonov-solid Sep 19, 2023
da1e5bb
todos
danylo-safonov-solid Sep 19, 2023
f4608b0
upd
danylo-safonov-solid Sep 19, 2023
6cf6999
constructor
danylo-safonov-solid Sep 19, 2023
0e7420e
parse
danylo-safonov-solid Sep 19, 2023
f6d6608
todo
danylo-safonov-solid Sep 19, 2023
e6a36d0
upd
danylo-safonov-solid Sep 20, 2023
d1080ab
Merge branch 'main' into PoolClient
danylo-safonov-solid Sep 20, 2023
2a99e77
upd
danylo-safonov-solid Sep 20, 2023
b396b87
fix comments
danylo-safonov-solid Sep 20, 2023
be46787
upd
danylo-safonov-solid Sep 20, 2023
63bb9de
upd
danylo-safonov-solid Sep 20, 2023
08caea6
upd
danylo-safonov-solid Sep 20, 2023
ac91006
constructor
danylo-safonov-solid Sep 20, 2023
f5c5768
upd
danylo-safonov-solid Sep 20, 2023
24cb622
upd
danylo-safonov-solid Sep 20, 2023
68545d5
export
danylo-safonov-solid Sep 20, 2023
1eafda3
tls options
danylo-safonov-solid Sep 20, 2023
8cfa653
finish?
danylo-safonov-solid Sep 20, 2023
e671dcc
upd
danylo-safonov-solid Sep 20, 2023
f1b6395
last
danylo-safonov-solid Sep 20, 2023
67aab73
Merge branch 'PoolClient' into QueryResult
danylo-safonov-solid Sep 20, 2023
ac208bc
upd
danylo-safonov-solid Sep 20, 2023
26f47f3
upd
danylo-safonov-solid Sep 20, 2023
986eed2
upd
danylo-safonov-solid Sep 20, 2023
d4542bb
sync
danylo-safonov-solid Sep 20, 2023
1769b88
revert
danylo-safonov-solid Sep 20, 2023
d092ed9
revert
danylo-safonov-solid Sep 20, 2023
5f4ad6c
upd
danylo-safonov-solid Sep 20, 2023
dbc929f
upd
danylo-safonov-solid Sep 20, 2023
74d4e6e
sync
danylo-safonov-solid Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/deno_postgres_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export 'src/pool.dart';
export 'src/pool_client.dart';
export 'src/query.dart';
export 'src/query_client.dart';
export 'src/query_object.dart' show QueryArguments;
export 'src/query_object_result.dart';
export 'src/query_result.dart';
export 'src/tls_options.dart';
Expand Down
102 changes: 102 additions & 0 deletions lib/src/client_common.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import 'package:deno_postgres_interop/src/query_array_result.dart';
import 'package:deno_postgres_interop/src/query_object_options.dart';
import 'package:deno_postgres_interop/src/query_object_result.dart';
import 'package:deno_postgres_interop/src/util.dart';

/// [deno-postgres@v0.17.0/QueryArguments](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryArguments).
typedef QueryArguments = Object;

/// This class hosts common interops for clients.
class ClientCommon {
/// [deno-postgres@v0.17.0/Transaction/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryArray_0).
/// [deno-postgres@v0.17.0/QueryClient/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryArray_0).
static Future<QueryArrayResult<T>> queryArray<T extends List<dynamic>>(
Object queryable,
String query, [
QueryArguments? arguments,
]) =>
_query('queryArray', queryable, query, arguments);

/// [deno-postgres@v0.17.0/Transaction/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryArray_1).
/// [deno-postgres@v0.17.0/QueryClient/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryArray_1).
static Future<QueryArrayResult<T>>
queryArrayWithOptions<T extends List<dynamic>>(
Object queryable,
QueryObjectOptions config,
) =>
callFutureMethod(queryable, 'queryArray', [config]);

// This one won't be implemented because it doesn't make much sense for dart,
// the query here is of type TemplateStringsArray which is used in
// [tagged templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates).
//
// [related issue](https://github.com/dart-lang/language/issues/1988).
//
// queryArray<T extends Array<unknown>>(
// strings: TemplateStringsArray,
// ...args: unknown[],
// ): Promise<QueryArrayResult<T>>
// https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryArray_2

/// [deno-postgres@v0.17.0/Transaction/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryObject_0).
/// [deno-postgres@v0.17.0/QueryClient/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryObject_0).
static Future<QueryObjectResult<T>> queryObject<T>(
Object queryable,
String query, [
QueryArguments? arguments,
]) =>
_query('queryObject', queryable, query, arguments);

/// [deno-postgres@v0.17.0/Transaction/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryObject_1).
/// [deno-postgres@v0.17.0/QueryClient/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryObject_1).
static Future<QueryObjectResult<T>> queryObjectWithOptions<T>(
Object queryable,
QueryObjectOptions config,
) =>
callFutureMethod(queryable, 'queryObject', [config]);

// This one won't be implemented because it doesn't make much sense for dart,
// the query here is of type TemplateStringsArray which is used in
// [tagged templates](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates).
//
// [related issue](https://github.com/dart-lang/language/issues/1988).
//
// [deno-postgres@v0.17.0/QueryClient/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryObject_2).
// Future<QueryObjectResult<T>> queryObjectWithOptions<T>(
// List<String> query,
// List args,
// ) =>
// throw UnimplementedError();

static Future<T> _query<T>(
String function,
Object queryable,
String query, [
QueryArguments? arguments,
]) {
_assertQueryArgumentsOrNull(arguments);

return callFutureMethod(
queryable,
function,
[
query,
if (arguments != null) arguments,
],
);
}
}

void _assertQueryArgumentsOrNull(QueryArguments? arguments) {
final isCorrectType = arguments is List ||
arguments is Map<String, dynamic> ||
arguments == null;

if (!isCorrectType) {
throw ArgumentError.value(
arguments,
'arguments',
'Accepted types are List<any> and Map<String, any>.',
);
}
}
2 changes: 1 addition & 1 deletion lib/src/query.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/src/client_common.dart';
import 'package:deno_postgres_interop/src/encoded_arg.dart';
import 'package:deno_postgres_interop/src/query_object.dart';
import 'package:deno_postgres_interop/src/query_object_options.dart';
import 'package:deno_postgres_interop/src/result_type.dart';

Expand Down
14 changes: 14 additions & 0 deletions lib/src/query_array_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'dart:js_interop';

import 'package:deno_postgres_interop/src/query.dart';
import 'package:deno_postgres_interop/src/query_result.dart';

/// [deno-postgres@v0.17.0/QueryArrayResult](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryArrayResult).
@JS()
class QueryArrayResult<T extends List<dynamic>> extends QueryResult {
/// [deno-postgres@v0.17.0/QueryArrayResult/rows](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryArrayResult#prop_rows).
external List<T> get rows;

/// [deno-postgres@v0.17.0/QueryResult/constructor](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryResult#ctor_0).
external factory QueryArrayResult(Query query);
}
25 changes: 23 additions & 2 deletions lib/src/query_client.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/src/query_object.dart';
import 'package:deno_postgres_interop/src/client_common.dart';
import 'package:deno_postgres_interop/src/query_array_result.dart';
import 'package:deno_postgres_interop/src/query_object_options.dart';
import 'package:deno_postgres_interop/src/query_object_result.dart';
import 'package:deno_postgres_interop/src/transaction.dart';
import 'package:deno_postgres_interop/src/transaction_options.dart';
Expand Down Expand Up @@ -46,10 +48,29 @@ extension QueryClientProps on QueryClient {
return result;
}

/// [deno-postgres@v0.17.0/QueryClient/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryArray_0).
Future<QueryArrayResult<T>> queryArray<T extends List<dynamic>>(
String query, [
QueryArguments? args,
]) =>
ClientCommon.queryArray(this, query, args);

/// [deno-postgres@v0.17.0/QueryClient/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryArray_1).
Future<QueryArrayResult<T>> queryArrayWithOptions<T extends List<dynamic>>(
QueryObjectOptions config,
) =>
ClientCommon.queryArrayWithOptions(this, config);

/// [deno-postgres@v0.17.0/QueryClient/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryObject_0).
Future<QueryObjectResult<T>> queryObject<T>(
String query, [
QueryArguments? arguments,
]) =>
queryObjectCommon(this, query, arguments);
ClientCommon.queryObject(this, query, arguments);

/// [deno-postgres@v0.17.0/QueryClient/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#method_queryObject_1).
Future<QueryObjectResult<T>> queryObjectWithOptions<T>(
QueryObjectOptions config,
) =>
ClientCommon.queryObjectWithOptions(this, config);
}
36 changes: 0 additions & 36 deletions lib/src/query_object.dart

This file was deleted.

10 changes: 5 additions & 5 deletions lib/src/query_object_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import 'dart:js_util';

import 'package:deno_postgres_interop/src/query_options.dart';

/// [deno-postgres@v0.17.0/QueryObjectOptions](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryObjectOptions).
/// [deno-postgres@v0.17.0/QueryObjectOptions](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryObjectOptions).
@JS()
class QueryObjectOptions extends QueryOptions {
/// [deno-postgres@v0.17.0/QueryObjectOptions/fields](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryObjectOptions#prop_fields).
/// [deno-postgres@v0.17.0/QueryObjectOptions/fields](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#prop_fields).
external List<String>? get fields;

/// [deno-postgres@v0.17.0/QueryObjectOptions](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryObjectOptions).
/// [deno-postgres@v0.17.0/QueryObjectOptions](https://deno.land/x/postgres@v0.17.0/query/mod.ts?s=QueryObjectOptions).
factory QueryObjectOptions({List<String>? fields, bool? isCamelCase}) =>
jsify(
{
Expand All @@ -19,8 +19,8 @@ class QueryObjectOptions extends QueryOptions {
) as QueryObjectOptions;
}

/// [deno-postgres@v0.17.0/QueryObjectOptions](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryObjectOptions).
/// [deno-postgres@v0.17.0/QueryObjectOptions](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryObjectOptions).
extension QueryObjectOptionsProps on QueryObjectOptions {
/// [deno-postgres@v0.17.0/QueryObjectOptions/camelcase](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryObjectOptions#prop_camelcase).
/// [deno-postgres@v0.17.0/QueryObjectOptions/camelcase](https://deno.land/x/postgres@v0.17.0/mod.ts?s=QueryClient#prop_camelcase).
bool? get isCamelCase => getProperty(this, 'camelcase');
}
2 changes: 1 addition & 1 deletion lib/src/query_options.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/deno_postgres_interop.dart';
import 'package:deno_postgres_interop/src/client_common.dart';
import 'package:deno_postgres_interop/src/encoded_arg.dart';

/// [deno-postgres@v0.17.0/QueryOptions](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=QueryOptions).
Expand Down
2 changes: 1 addition & 1 deletion lib/src/result_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// [postgres@v0.17.0/ResultType](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=ResultType).
/// [deno-postgres@v0.17.0/ResultType](https://deno.land/x/postgres@v0.17.0/query/query.ts?s=ResultType).
enum ResultType {
/// array.
array,
Expand Down
25 changes: 23 additions & 2 deletions lib/src/transaction.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:js_interop';

import 'package:deno_postgres_interop/src/query_object.dart';
import 'package:deno_postgres_interop/src/client_common.dart';
import 'package:deno_postgres_interop/src/query_array_result.dart';
import 'package:deno_postgres_interop/src/query_object_options.dart';
import 'package:deno_postgres_interop/src/query_object_result.dart';
import 'package:deno_postgres_interop/src/util.dart';

Expand All @@ -16,10 +18,29 @@ extension TransactionProps on Transaction {
/// [deno-postgres@v0.17.0/Transaction/commit](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_commit_0).
Future<void> commit() => callFutureMethod(this, 'commit');

/// [deno-postgres@v0.17.0/Transaction/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryArray_0).
Future<QueryArrayResult<T>> queryArray<T extends List<dynamic>>(
String query, [
QueryArguments? args,
]) =>
ClientCommon.queryArray(this, query, args);

/// [deno-postgres@v0.17.0/Transaction/queryArray](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryArray_1).
Future<QueryArrayResult<T>> queryArrayWithOptions<T extends List<dynamic>>(
QueryObjectOptions config,
) =>
ClientCommon.queryArrayWithOptions(this, config);

/// [deno-postgres@v0.17.0/Transaction/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryObject_0).
Future<QueryObjectResult<T>> queryObject<T>(
String query, [
QueryArguments? arguments,
]) =>
queryObjectCommon(this, query, arguments);
ClientCommon.queryObject(this, query, arguments);

/// [deno-postgres@v0.17.0/Transaction/queryObject](https://deno.land/x/postgres@v0.17.0/mod.ts?s=Transaction#method_queryObject_1).
Future<QueryObjectResult<T>> queryObjectWithOptions<T>(
QueryObjectOptions config,
) =>
ClientCommon.queryObjectWithOptions(this, config);
}
Loading