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

Notice #16

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Future<Response> fetch(Request _) async {
return Response(
[
result.command == CommandType.select,
'warnings = ${result.warnings}',
'''
rowDescription =
columnCount = ${result.rowDescription?.columnCount}
columns =
${result.rowDescription?.columns.map((e) => ' name = ${e.name}').join('\n')}
''',
result.query.resultType,
...result.rows.map(rowToPrettyString),
].join('\n\n'),
Expand Down
68 changes: 68 additions & 0 deletions lib/src/column.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import 'dart:js_interop';
import 'dart:js_util';

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
@JS()
class Column {
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
external String get name;

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
external int get tableOid;

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
external int get index;

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
external int get typeOid;

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
external int get columnLength;

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
external int get typeModifier;

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column#ctor_0).
factory Column({
required String name,
required int tableOid,
required int index,
required int typeOid,
required int columnLength,
required int typeModifier,
required ColumnFormat format,
}) =>
callConstructor('Column', [
name,
tableOid,
index,
typeOid,
columnLength,
typeModifier,
format.id,
]);
}

/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
extension ColumnProps on Column {
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
ColumnFormat get format => ColumnFormat.values
.firstWhere((e) => e.id == getProperty(this, 'format'));
}

/// enum Format {
/// TEXT = 0,
/// BINARY = 1,
/// }
enum ColumnFormat {
/// text.
text(0),

/// binary.
binary(1);

/// Used for interop.
final int id;

const ColumnFormat(this.id);
}
98 changes: 98 additions & 0 deletions lib/src/notice.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import 'dart:js_interop';
import 'dart:js_util';

/// [[email protected]/Notice](https://deno.land/x/[email protected]/connection/message.ts?s=Notice).
@JS()
class Notice {
/// [[email protected]/Notice/severity](https://deno.land/x/[email protected]/connection/message.ts?s=Notice#prop_severity).
external String get severity;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/// [[email protected]/Notice](https://deno.land/x/[email protected]/connection/message.ts?s=Notice).
factory Notice({
required String severity,
required String code,
required String message,
String? detail,
String? hint,
String? position,
String? internalPosition,
String? internalQuery,
String? where,
String? schema,
String? table,
String? column,
String? dataType,
String? constraint,
String? file,
String? line,
String? routine,
}) {
return jsify({
'severity': severity,
'code': code,
'message': message,
if (detail != null) 'detail': detail,
if (hint != null) 'hint': hint,
if (position != null) 'position': position,
if (internalPosition != null) 'internalPosition': internalPosition,
if (internalQuery != null) 'internalQuery': internalQuery,
if (where != null) 'where': where,
if (schema != null) 'schema': schema,
if (table != null) 'table': table,
if (column != null) 'column': column,
if (dataType != null) 'dataType': dataType,
if (constraint != null) 'constraint': constraint,
if (file != null) 'file': file,
if (line != null) 'line': line,
if (routine != null) 'routine': routine,
}) as Notice;
}
}
8 changes: 8 additions & 0 deletions lib/src/query_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import 'dart:js_interop';
import 'dart:js_util';

import 'package:deno_postgres_interop/src/command_type.dart';
import 'package:deno_postgres_interop/src/notice.dart';
import 'package:deno_postgres_interop/src/query.dart';
import 'package:deno_postgres_interop/src/row_description.dart';

/// [[email protected]/QueryResult](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult).
@JS()
class QueryResult {
/// [[email protected]/QueryResult/warnings](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult#prop_warnings).
external List<Notice> get warnings;

/// [[email protected]/QueryResult/constructor](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult#ctor_0).
external Query get query;

/// [[email protected]/QueryResult/rowDescription](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult#accessor_rowDescription).
external RowDescription? get rowDescription;
}

/// [[email protected]/QueryResult](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult).
Expand Down
16 changes: 16 additions & 0 deletions lib/src/row_description.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:js_interop';

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

/// [[email protected]/RowDescription](https://deno.land/x/[email protected]/query/query.ts?s=RowDescription).
@JS()
class RowDescription {
/// https://deno.land/x/[email protected]/query/query.ts?s=RowDescription#ctor_0
external int get columnCount;

/// https://deno.land/x/[email protected]/query/query.ts?s=RowDescription#ctor_0
external List<Column> get columns;

/// https://deno.land/x/[email protected]/query/query.ts?s=RowDescription#ctor_0
external factory RowDescription(int columnCount, List<Column> columns);
}