Skip to content

Commit a78d81d

Browse files
committed
create example. update dependencies, etc.
1 parent d9debf6 commit a78d81d

File tree

6 files changed

+124
-31
lines changed

6 files changed

+124
-31
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 codeux.design / Herbert Poul
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
A library for Dart developers.
1+
A few utilities to make it easier to work with postgresql database.
22

3-
Created from templates made available by Stagehand under a BSD-style
4-
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE).
3+
Uses the pub [postgres](https://pub.dev/packages/postgres) package internally
54

65
## Usage
76

8-
A simple usage example:
7+
see [example/lib/main.dart](example/lib/main.dart).
98

10-
```dart
11-
import 'package:postgres_utils/postgres_utils.dart';
9+
## Examples
1210

13-
main() {
14-
var awesome = new Awesome();
15-
}
16-
```
11+
Check out https://github.com/authpass/authpass-cloud for a project using this package.
1712

1813
## Features and bugs
1914

2015
Please file feature requests and bugs at the [issue tracker][tracker].
2116

22-
[tracker]: http://example.com/issues/replaceme
17+
[tracker]: https://github.com/authpass/postgres_utils.dart/issues

example/lib/main.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:postgres/postgres.dart';
2+
import 'package:postgres_utils/postgres_utils.dart';
3+
4+
class DatabaseTransaction extends DatabaseTransactionBase<MyTables> {
5+
DatabaseTransaction(PostgreSQLExecutionContext conn, MyTables tables)
6+
: super(conn, tables);
7+
}
8+
9+
class DatabaseAccess extends DatabaseAccessBase<DatabaseTransaction, MyTables> {
10+
DatabaseAccess({
11+
required DatabaseConfig config,
12+
}) : super(
13+
config: config,
14+
tables: MyTables(),
15+
migrations: MyMigrationsProvider(),
16+
);
17+
18+
@override
19+
DatabaseTransaction createDatabaseTransaction(
20+
PostgreSQLExecutionContext conn, MyTables tables) {
21+
return DatabaseTransaction(conn, tables);
22+
}
23+
}
24+
25+
class MyTables extends TablesBase {
26+
MyTables();
27+
28+
late final UserTable user = UserTable();
29+
@override
30+
List<TableBase> get tables => [
31+
user,
32+
];
33+
}
34+
35+
class UserTable extends TableBase {
36+
UserTable();
37+
38+
static const TABLE_USER = 'user';
39+
40+
@override
41+
List<String> get tables => [
42+
TABLE_USER,
43+
];
44+
45+
Future<void> createTables(DatabaseTransaction db) async {
46+
await db.execute('''
47+
CREATE TABLE $TABLE_USER (id uuid primary key, username varchar)
48+
''');
49+
}
50+
}
51+
52+
class MyMigrationsProvider
53+
extends MigrationsProvider<DatabaseTransaction, MyTables> {
54+
@override
55+
List<Migrations<DatabaseTransaction, MyTables>> get migrations {
56+
return [
57+
Migrations(
58+
id: 1,
59+
up: (conn) async {
60+
await conn.tables.user.createTables(conn);
61+
}),
62+
];
63+
}
64+
}

example/pubspec.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: example
2+
description: Example app
3+
# version: 1.0.0
4+
# homepage: https://www.example.com
5+
6+
environment:
7+
sdk: '>=2.12.0 <3.0.0'
8+
9+
dependencies:
10+
postgres: ^2.4.1+2
11+
postgres_utils:
12+
path: ../

lib/src/config.g.dart

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: postgres_utils
2-
description: A starting point for Dart libraries or applications.
3-
# version: 1.0.0
4-
# homepage: https://www.example.com
2+
description: A few utils for working with postgresql databases.
3+
version: 1.0.0
4+
homepage: https://github.com/authpass/postgres_utils.dart
5+
issue_tracker: https://github.com/authpass/postgres_utils.dart/issues
56

67
environment:
78
sdk: '>=2.12.0 <3.0.0'
@@ -15,7 +16,7 @@ dependencies:
1516
json_annotation: ^4.0.1
1617

1718
dev_dependencies:
18-
json_serializable: ^4.1.0
19+
json_serializable: ^5.0.0
1920
pedantic: ^1.11.0
2021
test: ^1.16.8
21-
build_runner: ^1.10.0
22+
build_runner: ^2.1.2

0 commit comments

Comments
 (0)