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

PoolClient #17

Merged
merged 27 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions lib/deno_postgres_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
library;

export 'src/client.dart';
export 'src/client_configuration.dart';
export 'src/client_options.dart';
export 'src/command_type.dart';
export 'src/connection_options.dart';
export 'src/isolation_level.dart';
export 'src/partial/partial_connection_options.dart';
export 'src/partial/partial_tls_options.dart';
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';
export 'src/transaction.dart';
export 'src/transaction_options.dart';
export 'src/transport.dart';
69 changes: 69 additions & 0 deletions lib/src/client_configuration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/src/connection_options.dart';
import 'package:deno_postgres_interop/src/tls_options.dart';
import 'package:deno_postgres_interop/src/transport.dart';

/// [[email protected]/ClientConfiguration](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration).
@JS()
class ClientConfiguration {
/// [[email protected]/ClientConfiguration/applicationName](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_applicationName).
external String get applicationName;

/// [[email protected]/ClientConfiguration/connection](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_connection).
external ConnectionOptions get connection;

/// [[email protected]/ClientConfiguration/database](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_database).
external String get database;

/// [[email protected]/ClientConfiguration/hostname](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_hostname).
external String get hostname;

/// [[email protected]/ClientConfiguration/options](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_options).
external Map<String, String> get options;

/// [[email protected]/ClientConfiguration/password](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_password).
external String? get password;

/// [[email protected]/ClientConfiguration/port](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_port).
external int get port;

/// [[email protected]/ClientConfiguration/tls](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_tls).
external TLSOptions get tls;

/// [[email protected]/ClientConfiguration/user](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_user).
external String get user;

/// [[email protected]/ClientConfiguration](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration).
factory ClientConfiguration({
required String applicationName,
required ConnectionOptions connection,
required String database,
required String hostname,
required String options,
required int port,
required TLSOptions tls,
required String user,
required Transport hostType,
String? password,
}) =>
jsify({
'applicationName': applicationName,
'connection': connection,
'database': database,
'hostname': hostname,
'options': options,
if (password != null) 'password': password,
'port': port,
'tls': tls,
'user': user,
'hostType': hostType.name,
}) as ClientConfiguration;
}

/// [[email protected]/ClientConfiguration](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration).
extension ClientConfigurationProps on ClientConfiguration {
/// [[email protected]/ClientConfiguration/host_type](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ClientConfiguration#prop_host_type).
Transport get hostType => Transport.parse(getProperty(this, 'host_type'));
}
129 changes: 129 additions & 0 deletions lib/src/client_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/src/partial/partial_connection_options.dart';
import 'package:deno_postgres_interop/src/partial/partial_tls_options.dart';
import 'package:deno_postgres_interop/src/transport.dart';

/// [[email protected]/ClientOptions](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions).
@JS()
class ClientOptions {
/// [[email protected]/ClientOptions/applicationName](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_applicationName).
external String? get applicationName;

/// [[email protected]/ClientOptions/database](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_database).
external String? get database;

/// [[email protected]/ClientOptions/hostname](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_hostname).
external String? get hostname;

/// [[email protected]/ClientOptions/password](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_password).
external String? get password;

/// [[email protected]/ClientOptions/user](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_applicationName/user).
external String? get user;

/// [[email protected]/ClientOptions](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions).
factory ClientOptions({
String? applicationName,
PartialConnectionOptions? connection,
String? database,
String? hostname,
Transport? hostType,
String? optionsString,
Map<String, String>? optionsMap,
String? password,
String? portString,
int? port,
PartialTLSOptions? tls,
String? user,
}) {
assert(optionsString == null || optionsMap == null);
assert(portString == null || port == null);

return jsify(
{
if (applicationName != null) 'applicationName': applicationName,
if (connection != null) 'connection': jsify(connection.asMap()),
if (database != null) 'database': database,
if (hostname != null) 'hostname': hostname,
if (hostType != null) 'host_type': hostType.name,
if (optionsString != null)
'options': optionsString
else if (optionsMap != null)
'options': jsify(optionsMap),
if (password != null) 'password': password,
if (portString != null)
'port': portString
else if (port != null)
'port': port,
if (tls != null) 'tls': jsify(tls.asMap()),
if (user != null) 'user': user,
},
) as ClientOptions;
}
}

/// [[email protected]/ClientOptions](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions).
extension ClientOptionsProps on ClientOptions {
/// [[email protected]/ClientOptions/host_type](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_host_type).
Transport get hostType => Transport.parse(getProperty(this, 'host_type'));

/// [[email protected]/ClientOptions/options](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_options).
///
/// Either this or [optionsMap] is null.
String? get optionsString {
final prop = getProperty(this, 'options');

return prop is String ? prop : null;
}

/// [[email protected]/ClientOptions/options](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_options).
///
/// Either this or [optionsString] is null.
Map<String, String>? get optionsMap {
final prop = getProperty(this, 'options');

return prop is String ? null : prop as Map<String, String>;
}

/// [[email protected]/ClientOptions/port](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_port).
///
/// Either this or [port] is null.
String? get portString {
final prop = getProperty(this, 'port');

return prop is String ? prop : null;
}

/// [[email protected]/ClientOptions/port](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_port).
///
/// Either this or [portString] is null.
int? get port {
final prop = getProperty(this, 'port');

return prop is int ? prop : null;
}
illia-romanenko marked this conversation as resolved.
Show resolved Hide resolved

/// [[email protected]/ClientOptions/connection](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_connection).
PartialConnectionOptions? get connection {
final map =
dartify(getProperty(this, 'connection')) as Map<dynamic, dynamic>?;

return map == null ? null : PartialConnectionOptions.fromMap(map);
}

/// [[email protected]/ClientOptions/tls](https://deno.land/x/[email protected]/mod.ts?s=ClientOptions#prop_tls).
PartialTLSOptions? get tls {
final map =
dartify(getProperty(this, 'connection')) as Map<dynamic, dynamic>?;

if (map == null) return null;

return PartialTLSOptions(
caCertificates: map['caCertificates'] as List<String>?,
isEnabled: map['enabled'] as bool?,
isEnforced: map['enforced'] as bool?,
);
}
}
47 changes: 47 additions & 0 deletions lib/src/connection_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/src/partial/partial_connection_options.dart';

/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions).
@JS()
class ConnectionOptions {
/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions#prop_attempts).
external int get attempts;

/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions).
factory ConnectionOptions({
required int attempts,
int Function(int previousInterval)? nextInterval,
int? interval,
}) {
return jsify(
PartialConnectionOptions(
attempts: attempts,
nextInterval: nextInterval,
interval: interval,
).asMap(),
) as ConnectionOptions;
}
}

/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions).
extension ConnectionOptionsProps on ConnectionOptions {
/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions#prop_interval).
///
/// Either this or [interval] is null.
int Function(int previousInterval)? get nextInterval {
final prop = getProperty(this, 'interval');

return prop is int ? null : prop as int Function(int previousInterval);
}

/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions#prop_interval).
///
/// Either this or [nextInterval] is null.
int? get interval {
final prop = getProperty(this, 'interval');

return prop is int ? prop : null;
}
}
8 changes: 4 additions & 4 deletions lib/src/isolation_level.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/// [[email protected]/Transaction Isolation](https://www.postgresql.org/docs/current/transaction-iso.html).
/// [Transaction Isolation](https://www.postgresql.org/docs/current/transaction-iso.html).
enum IsolationLevel {
/// [[email protected]/Transaction Isolation/Read Committed Isolation Level](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-READ-COMMITTED).
/// [Transaction Isolation/Read Committed Isolation Level](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-READ-COMMITTED).
readCommitted,

/// [[email protected]/Transaction Isolation/Repeatable Read Isolation Level](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-REPEATABLE-READ).
/// [Transaction Isolation/Repeatable Read Isolation Level](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-REPEATABLE-READ).
repeatableRead,

/// [[email protected]/Transaction Isolation/Serializable Isolation Level](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE).
/// [Transaction Isolation/Serializable Isolation Level](https://www.postgresql.org/docs/current/transaction-iso.html#XACT-SERIALIZABLE).
serializable;

/// Parses a string containing an [IsolationLevel] literal into its instance.
Expand Down
46 changes: 46 additions & 0 deletions lib/src/partial/partial_connection_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions).
class PartialConnectionOptions {
/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions#prop_attempts).
final int? attempts;

/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions#prop_interval).
///
/// Either this or [interval] is null.
final int Function(int previousInterval)? nextInterval;

/// [[email protected]/ConnectionOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=ConnectionOptions#prop_interval).
///
/// Either this or [nextInterval] is null.
final int? interval;

/// constructor.
PartialConnectionOptions({
this.attempts,
this.nextInterval,
this.interval,
}) : assert(interval == null || nextInterval == null);

/// used for interop.
factory PartialConnectionOptions.fromMap(Map<dynamic, dynamic> map) {
final intervalProp = map['interval'];

return PartialConnectionOptions(
attempts: map['attempts'] as int?,
interval: intervalProp is int ? intervalProp : null,
nextInterval: intervalProp is! int
? intervalProp as int Function(int previousInterval)?
: null,
);
}

/// used for jsify.
Map<String, dynamic> asMap() {
return {
if (attempts != null) 'attempts': attempts,
if (nextInterval != null)
'interval': nextInterval
else if (interval != null)
'interval': interval,
};
}
}
33 changes: 33 additions & 0 deletions lib/src/partial/partial_tls_options.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/// [[email protected]/TLSOptions](https://deno.land/x/[email protected]/connection/connection_params.ts?s=TLSOptions).
class PartialTLSOptions {
/// [[email protected]/TLSOptions/enabled](https://deno.land/x/[email protected]/connection/connection_params.ts?s=TLSOptions#prop_enabled).
final bool? isEnabled;

/// [[email protected]/TLSOptions/enfroce](https://deno.land/x/[email protected]/connection/connection_params.ts?s=TLSOptions#prop_enfroce).
final bool? isEnforced;

/// [[email protected]/TLSOptions/caCertificates](https://deno.land/x/[email protected]/connection/connection_params.ts?s=TLSOptions#prop_caCertificates).
final List<String>? caCertificates;

/// constructor.
PartialTLSOptions({
this.isEnabled,
this.isEnforced,
this.caCertificates,
});

/// used for interop.
PartialTLSOptions.fromMap(Map<dynamic, dynamic> map)
: caCertificates = map['caCertificates'] as List<String>?,
isEnabled = map['enabled'] as bool?,
isEnforced = map['enforced'] as bool?;

/// used for jsify.
Map<String, dynamic> asMap() {
return {
if (isEnabled != null) 'enabled': isEnabled,
if (isEnforced != null) 'enforce': isEnforced,
if (caCertificates != null) 'caCertificates': caCertificates,
};
}
}
Loading