Skip to content

Commit 4e228f6

Browse files
RowDescription (#15)
* init * upd
1 parent fb5f81b commit 4e228f6

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

example/lib/main.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Future<Response> fetch(Request _) async {
1919
return Response(
2020
[
2121
result.command == CommandType.select,
22+
'''
23+
rowDescription =
24+
columnCount = ${result.rowDescription?.columnCount}
25+
columns =
26+
${result.rowDescription?.columns.map((e) => ' name = ${e.name}').join('\n')}
27+
''',
2228
result.query.resultType,
2329
...result.rows.map(rowToPrettyString),
2430
].join('\n\n'),

lib/src/column.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'dart:js_interop';
2+
import 'dart:js_util';
3+
4+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
5+
@JS()
6+
class Column {
7+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
8+
external String get name;
9+
10+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
11+
external int get tableOid;
12+
13+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
14+
external int get index;
15+
16+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
17+
external int get typeOid;
18+
19+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
20+
external int get columnLength;
21+
22+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
23+
external int get typeModifier;
24+
25+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column#ctor_0).
26+
factory Column({
27+
required String name,
28+
required int tableOid,
29+
required int index,
30+
required int typeOid,
31+
required int columnLength,
32+
required int typeModifier,
33+
required ColumnFormat format,
34+
}) =>
35+
callConstructor('Column', [
36+
name,
37+
tableOid,
38+
index,
39+
typeOid,
40+
columnLength,
41+
typeModifier,
42+
format.id,
43+
]);
44+
}
45+
46+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
47+
extension ColumnProps on Column {
48+
/// [[email protected]/Column](https://deno.land/x/[email protected]/query/decode.ts?s=Column).
49+
ColumnFormat get format => ColumnFormat.values
50+
.firstWhere((e) => e.id == getProperty(this, 'format'));
51+
}
52+
53+
/// enum Format {
54+
/// TEXT = 0,
55+
/// BINARY = 1,
56+
/// }
57+
enum ColumnFormat {
58+
/// text.
59+
text(0),
60+
61+
/// binary.
62+
binary(1);
63+
64+
/// Used for interop.
65+
final int id;
66+
67+
const ColumnFormat(this.id);
68+
}

lib/src/query_result.dart

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

44
import 'package:deno_postgres_interop/src/command_type.dart';
55
import 'package:deno_postgres_interop/src/query.dart';
6+
import 'package:deno_postgres_interop/src/row_description.dart';
67

78
/// [[email protected]/QueryResult](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult).
89
@JS()
910
class QueryResult {
1011
/// [[email protected]/QueryResult/constructor](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult#ctor_0).
1112
external Query get query;
13+
14+
/// [[email protected]/QueryResult/rowDescription](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult#accessor_rowDescription).
15+
external RowDescription? get rowDescription;
1216
}
1317

1418
/// [[email protected]/QueryResult](https://deno.land/x/[email protected]/query/query.ts?s=QueryResult).

lib/src/row_description.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'dart:js_interop';
2+
3+
import 'package:deno_postgres_interop/src/column.dart';
4+
5+
/// [[email protected]/RowDescription](https://deno.land/x/[email protected]/query/query.ts?s=RowDescription).
6+
@JS()
7+
class RowDescription {
8+
/// https://deno.land/x/[email protected]/query/query.ts?s=RowDescription#ctor_0
9+
external int get columnCount;
10+
11+
/// https://deno.land/x/[email protected]/query/query.ts?s=RowDescription#ctor_0
12+
external List<Column> get columns;
13+
14+
/// https://deno.land/x/[email protected]/query/query.ts?s=RowDescription#ctor_0
15+
external factory RowDescription(int columnCount, List<Column> columns);
16+
}

0 commit comments

Comments
 (0)