Skip to content

Commit 9afe900

Browse files
Errors (#18)
* 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 * jserror * upd * upd again * fix * fix * fix * fix * export * 130/130 pana * better description
1 parent 9a75f04 commit 9afe900

File tree

8 files changed

+95
-17
lines changed

8 files changed

+95
-17
lines changed

example/lib/main.dart

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,50 @@ Future<Response> fetch(Request _) async {
99

1010
final client = Client(dbUrl);
1111
await client.connect();
12-
final result = await client.transaction(
13-
'transaction',
14-
transaction,
15-
TransactionOptions(isolationLevel: IsolationLevel.serializable),
16-
);
17-
await client.end();
12+
try {
13+
final result = await client.transaction(
14+
'transaction',
15+
transaction,
16+
TransactionOptions(isolationLevel: IsolationLevel.serializable),
17+
);
18+
await client.end();
1819

19-
return Response(
20-
[
21-
result.command == CommandType.select,
22-
'warnings = ${result.warnings}',
23-
'''
20+
return Response(
21+
[
22+
result.command == CommandType.select,
23+
'warnings = ${result.warnings}',
24+
'''
2425
rowDescription =
2526
columnCount = ${result.rowDescription?.columnCount}
2627
columns =
2728
${result.rowDescription?.columns.map((e) => ' name = ${e.name}').join('\n')}
2829
''',
29-
result.query.resultType,
30-
...result.rows.map(rowToPrettyString),
31-
].join('\n\n'),
32-
);
30+
result.query.resultType,
31+
...result.rows.map(rowToPrettyString),
32+
].join('\n\n'),
33+
);
34+
} on TransactionError catch (e) {
35+
await client.end();
36+
37+
return Response('''
38+
${e.name}
39+
${e.cause}
40+
${e.cause.name}
41+
${e.cause.cause}
42+
${e.cause.message}
43+
${e.cause.fields}
44+
${e.message}
45+
$e
46+
''');
47+
}
3348
}
3449

3550
Future<QueryObjectResult<dynamic>> transaction(Transaction transaction) async {
3651
await transaction.queryObject(
3752
'UPDATE public."User" '
3853
r'SET username=$1 '
39-
"WHERE last_name='user'",
54+
"WHERE last_name='user'"
55+
'AND y = z',
4056
["'user${transaction.hashCode}'"],
4157
);
4258
await Future.delayed(const Duration(seconds: 10));

lib/deno_postgres_interop.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export 'src/command_type.dart';
99
export 'src/connection.dart';
1010
export 'src/connection_options.dart';
1111
export 'src/encoded_arg.dart';
12+
export 'src/errors/connection_error.dart';
13+
export 'src/errors/connection_params_error.dart';
14+
export 'src/errors/postgres_error.dart';
15+
export 'src/errors/transaction_error.dart';
1216
export 'src/isolation_level.dart';
1317
export 'src/notice.dart';
1418
export 'src/partial/partial_connection_options.dart';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:deno_postgres_interop/src/errors/js_error.dart';
4+
5+
/// [[email protected]/ConnectionError](https://deno.land/x/[email protected]/client/error.ts?s=ConnectionError).
6+
@JS('Error')
7+
class ConnectionError extends JSError {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:deno_postgres_interop/src/errors/js_error.dart';
4+
5+
/// [[email protected]/ConnectionParamsError](https://deno.land/x/[email protected]/client/error.ts?s=ConnectionParamsError).
6+
@JS('Error')
7+
class ConnectionParamsError extends JSError {}

lib/src/errors/js_error.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'dart:js_interop';
2+
3+
/// [js/Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error).
4+
@JS('Error')
5+
class JSError {
6+
/// [js/Error/name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name).
7+
external String get name;
8+
9+
/// [js/Error/cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause).
10+
external Error? get cause;
11+
12+
/// [js/Error/message](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message).
13+
external String get message;
14+
}

lib/src/errors/postgres_error.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:deno_postgres_interop/src/errors/js_error.dart';
4+
import 'package:deno_postgres_interop/src/notice.dart';
5+
6+
/// [[email protected]/PostgresError](https://deno.land/x/[email protected]/client/error.ts?s=TransactionError).
7+
@JS()
8+
class PostgresError extends JSError {
9+
/// [[email protected]/PostgresError](https://deno.land/x/[email protected]/client/error.ts?s=PostgresError#prop_fields).
10+
external Notice get fields;
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:deno_postgres_interop/src/errors/postgres_error.dart';
4+
5+
/// [[email protected]/TransactionError](https://deno.land/x/[email protected]/client/error.ts?s=TransactionError).
6+
@JS()
7+
class TransactionError {
8+
/// [js/Error/cause](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause).
9+
/// [[email protected]/TransactionError/constructor](https://deno.land/x/[email protected]/client/error.ts?s=TransactionError#ctor_0).
10+
external PostgresError get cause;
11+
12+
/// [js/Error/message](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message).
13+
external String get message;
14+
15+
/// [js/Error/name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name).
16+
external String get name;
17+
}

pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: deno_postgres_interop
2-
description: An interop for deno-postgres.
2+
description:
3+
An interop for js package deno-postgres - PostgreSQL
4+
driver that can be used in deno-deploy (supabase edge functions).
35
version: 0.0.1
46
repository: https://github.com/solid-software/deno_postgres_interop
57

0 commit comments

Comments
 (0)