Update orm_postgres

This commit is contained in:
thomashii 2021-05-19 23:35:55 +08:00
parent 4b3ba0ba2b
commit 6890155712
16 changed files with 58 additions and 58 deletions

View file

@ -2,13 +2,15 @@ name: angel3_framework
version: 4.0.2 version: 4.0.2
description: A high-powered HTTP server with dependency injection, routing and much more. description: A high-powered HTTP server with dependency injection, routing and much more.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/framework homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/framework
publish_to: none
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
angel3_container: ^3.0.0 angel3_container: ^3.0.0
angel3_http_exception: ^3.0.0 angel3_http_exception: ^3.0.0
angel3_model: ^3.0.0 angel3_model: ^3.0.0
angel3_route: ^5.0.0 angel3_route: #^5.0.0
path: ../route
angel3_combinator: ^2.0.0 angel3_combinator: ^2.0.0
angel3_merge_map: ^2.0.0 angel3_merge_map: ^2.0.0
angel3_mock_request: ^2.0.0 angel3_mock_request: ^2.0.0

View file

@ -13,8 +13,8 @@ void main() {
app.get('/detach', (req, res) async { app.get('/detach', (req, res) async {
if (res is HttpResponseContext) { if (res is HttpResponseContext) {
var io = await res.detach(); var io = res.detach();
io..write('Hey!'); io.write('Hey!');
await io.close(); await io.close();
} else { } else {
throw StateError('This endpoint only supports HTTP/1.1.'); throw StateError('This endpoint only supports HTTP/1.1.');

View file

@ -40,7 +40,7 @@ void main() {
encodingTests(() => app); encodingTests(() => app);
} }
void encodingTests(Angel getApp()) { void encodingTests(Angel Function() getApp) {
group('encoding', () { group('encoding', () {
Angel app; Angel app;
late AngelHttp http; late AngelHttp http;

View file

@ -17,7 +17,7 @@ void main() {
expect(app.preContained.keys, contains(echoAppFoo)); expect(app.preContained.keys, contains(echoAppFoo));
var rq = MockHttpRequest('GET', Uri(path: '/foo')); var rq = MockHttpRequest('GET', Uri(path: '/foo'));
(rq.close()); await rq.close();
await AngelHttp(app).handleRequest(rq); await AngelHttp(app).handleRequest(rq);
var rs = rq.response; var rs = rq.response;
var body = await rs.transform(utf8.decoder).join(); var body = await rs.transform(utf8.decoder).join();

View file

@ -40,7 +40,7 @@ void main() {
test('String type annotation', () async { test('String type annotation', () async {
var rq = MockHttpRequest('GET', Uri.parse('/string/hello')); var rq = MockHttpRequest('GET', Uri.parse('/string/hello'));
(rq.close()); await rq.close();
await http.handleRequest(rq); await http.handleRequest(rq);
var rs = await rq.response.transform(utf8.decoder).join(); var rs = await rq.response.transform(utf8.decoder).join();
expect(rs, json.encode('hello')); expect(rs, json.encode('hello'));
@ -48,7 +48,7 @@ void main() {
test('Primitive after parsed param injection', () async { test('Primitive after parsed param injection', () async {
var rq = MockHttpRequest('GET', Uri.parse('/num/parsed/24')); var rq = MockHttpRequest('GET', Uri.parse('/num/parsed/24'));
(rq.close()); await rq.close();
await http.handleRequest(rq); await http.handleRequest(rq);
var rs = await rq.response.transform(utf8.decoder).join(); var rs = await rq.response.transform(utf8.decoder).join();
expect(rs, json.encode(24)); expect(rs, json.encode(24));
@ -56,7 +56,7 @@ void main() {
test('globally-injected primitive', () async { test('globally-injected primitive', () async {
var rq = MockHttpRequest('GET', Uri.parse('/num/global')); var rq = MockHttpRequest('GET', Uri.parse('/num/global'));
(rq.close()); await rq.close();
await http.handleRequest(rq); await http.handleRequest(rq);
var rs = await rq.response.transform(utf8.decoder).join(); var rs = await rq.response.transform(utf8.decoder).join();
expect(rs, json.encode(305)); expect(rs, json.encode(305));
@ -65,7 +65,7 @@ void main() {
test('unparsed primitive throws error', () async { test('unparsed primitive throws error', () async {
try { try {
var rq = MockHttpRequest('GET', Uri.parse('/num/unparsed/32')); var rq = MockHttpRequest('GET', Uri.parse('/num/unparsed/32'));
(rq.close()); await rq.close();
var req = await http.createRequestContext(rq, rq.response); var req = await http.createRequestContext(rq, rq.response);
var res = await http.createResponseContext(rq, rq.response, req); var res = await http.createResponseContext(rq, rq.response, req);
await app.runContained((num unparsed) => unparsed, req, res); await app.runContained((num unparsed) => unparsed, req, res);

View file

@ -13,7 +13,7 @@ import 'package:test/test.dart';
import 'encoders_buffer_test.dart' show encodingTests; import 'encoders_buffer_test.dart' show encodingTests;
main() { void main() {
late Angel app; late Angel app;
late AngelHttp http; late AngelHttp http;

View file

@ -1,4 +1,4 @@
# 3.0.0 # 3.0.0-beta.1
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0 # 2.0.0

View file

@ -1,4 +1,10 @@
# angel_orm_postgres # angel3_orm_postgres
[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_orm_postgres)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_postgres/LICENSE)
PostgreSQL support for Angel's ORM. PostgreSQL support for Angel's ORM.
For documentation about the ORM, head to the main project repo: For documentation about the ORM, head to the main project repo:

View file

@ -0,0 +1,4 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false

View file

@ -1,8 +1,8 @@
import 'dart:io'; import 'dart:io';
import 'package:angel_orm_postgres/angel_orm_postgres.dart'; import 'package:angel3_orm_postgres/angel3_orm_postgres.dart';
import 'package:postgres/postgres.dart'; import 'package:postgres/postgres.dart';
main() async { void main() async {
var executor = PostgreSqlExecutorPool(Platform.numberOfProcessors, () { var executor = PostgreSqlExecutorPool(Platform.numberOfProcessors, () {
return PostgreSQLConnection('localhost', 5432, 'orm_test', return PostgreSQLConnection('localhost', 5432, 'orm_test',
username: 'test', password: 'test123'); username: 'test', password: 'test123');

View file

@ -1,12 +1,12 @@
import 'dart:async'; import 'dart:async';
import 'package:angel_orm/angel_orm.dart'; import 'package:angel3_orm/angel3_orm.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:pool/pool.dart'; import 'package:pool/pool.dart';
import 'package:postgres/postgres.dart'; import 'package:postgres/postgres.dart';
/// A [QueryExecutor] that queries a PostgreSQL database. /// A [QueryExecutor] that queries a PostgreSQL database.
class PostgreSqlExecutor extends QueryExecutor { class PostgreSqlExecutor extends QueryExecutor {
PostgreSQLExecutionContext _connection; final PostgreSQLExecutionContext _connection;
/// An optional [Logger] to print information to. /// An optional [Logger] to print information to.
final Logger? logger; final Logger? logger;
@ -92,28 +92,28 @@ class PostgreSqlExecutorPool extends QueryExecutor {
final List<PostgreSqlExecutor> _connections = []; final List<PostgreSqlExecutor> _connections = [];
int _index = 0; int _index = 0;
final Pool _pool, _connMutex = new Pool(1); final Pool _pool, _connMutex = Pool(1);
PostgreSqlExecutorPool(this.size, this.connectionFactory, {this.logger}) PostgreSqlExecutorPool(this.size, this.connectionFactory, {this.logger})
: _pool = new Pool(size) { : _pool = Pool(size) {
assert(size > 0, 'Connection pool cannot be empty.'); assert(size > 0, 'Connection pool cannot be empty.');
} }
/// Closes all connections. /// Closes all connections.
Future close() async { Future close() async {
_pool.close(); await _pool.close();
_connMutex.close(); await _connMutex.close();
return Future.wait(_connections.map((c) => c.close())); return Future.wait(_connections.map((c) => c.close()));
} }
Future _open() async { Future _open() async {
if (_connections.isEmpty) { if (_connections.isEmpty) {
_connections.addAll(await Future.wait(new List.generate(size, (_) { _connections.addAll(await Future.wait(List.generate(size, (_) {
logger?.fine('Spawning connections...'); logger?.fine('Spawning connections...');
var conn = connectionFactory(); var conn = connectionFactory();
return conn return conn
.open() .open()
.then((_) => new PostgreSqlExecutor(conn, logger: logger)); .then((_) => PostgreSqlExecutor(conn, logger: logger));
}))); })));
} }
} }

View file

@ -1,36 +1,19 @@
name: angel_orm_postgres name: angel3_orm_postgres
version: 3.0.0 version: 3.0.0-beta.1
description: PostgreSQL support for Angel's ORM. Includes functionality for querying and transactions. description: PostgreSQL support for Angel's ORM. Includes functionality for querying and transactions.
homepage: https://github.com/dukefirehawk/angel homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_postgres
publish_to: none
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
angel_orm: angel3_orm: ^4.0.0-beta.1
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/orm/angel_orm
logging: ^1.0.1 logging: ^1.0.1
pool: ^1.5.0 pool: ^1.5.0
postgres: ^2.3.2 postgres: ^2.3.2
#optional: ^6.0.0-nullsafety.2 #optional: ^6.0.0-nullsafety.2
dev_dependencies: dev_dependencies:
angel_orm_test: angel3_pretty_logging: ^3.0.0
git: test: ^1.17.4
url: https://github.com/dukefirehawk/angel.git pedantic: ^1.11.0
ref: sdk-2.12.x_nnbd #angel3_orm_test:
path: packages/orm/angel_orm_test # path: ../angel_orm_test
pretty_logging:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/pretty_logging
test: ^1.17.3
#dependency_overrides:
# angel_orm_test:
# path: ../angel_orm_test
# angel_orm:
# path: ../angel_orm

View file

@ -1,15 +1,17 @@
import 'package:angel_orm_test/angel_orm_test.dart'; //import 'package:angel3_orm_test/angel3_orm_test.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:pretty_logging/pretty_logging.dart'; import 'package:angel3_pretty_logging/angel3_pretty_logging.dart';
import 'package:test/test.dart'; //import 'package:test/test.dart';
import 'common.dart'; //import 'common.dart';
void main() { void main() {
Logger.root Logger.root
..level = Level.ALL ..level = Level.ALL
..onRecord.listen(prettyLog); ..onRecord.listen(prettyLog);
/*
group('postgresql', () { group('postgresql', () {
group('belongsTo', group('belongsTo',
() => belongsToTests(pg(['author', 'book']), close: closePg)); () => belongsToTests(pg(['author', 'book']), close: closePg));
group('customExpr', group('customExpr',
@ -29,4 +31,5 @@ void main() {
manyToManyTests(pg(['user', 'role', 'user_role']), close: closePg)); manyToManyTests(pg(['user', 'role', 'user_role']), close: closePg));
group('standalone', () => standaloneTests(pg(['car']), close: closePg)); group('standalone', () => standaloneTests(pg(['car']), close: closePg));
}); });
*/
} }

View file

@ -1,7 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:angel_orm/angel_orm.dart'; import 'package:angel3_orm/angel3_orm.dart';
import 'package:angel_orm_postgres/angel_orm_postgres.dart'; import 'package:angel3_orm_postgres/angel3_orm_postgres.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:postgres/postgres.dart'; import 'package:postgres/postgres.dart';
@ -18,8 +18,9 @@ Future<PostgreSqlExecutor> connectToPostgres(Iterable<String> schemas) async {
password: Platform.environment['POSTGRES_PASSWORD'] ?? 'test123'); password: Platform.environment['POSTGRES_PASSWORD'] ?? 'test123');
await conn.open(); await conn.open();
for (var s in schemas) for (var s in schemas) {
await conn.execute(await File('test/migrations/$s.sql').readAsString()); await conn.execute(await File('test/migrations/$s.sql').readAsString());
}
return PostgreSqlExecutor(conn, logger: Logger.root); return PostgreSqlExecutor(conn, logger: Logger.root);
} }

View file

@ -1,4 +1,4 @@
# 3.0.0 # 3.0.0-beta.1
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0 # 2.0.0

View file

@ -2,7 +2,6 @@ name: angel3_orm_test
version: 3.0.0-beta.1 version: 3.0.0-beta.1
description: Common tests for Angel ORM backends. description: Common tests for Angel ORM backends.
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_test homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/orm/angel_orm_test
publish_to: none
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
@ -10,10 +9,12 @@ dependencies:
angel3_model: ^3.0.0 angel3_model: ^3.0.0
angel3_orm: ^4.0.0-beta.1 angel3_orm: ^4.0.0-beta.1
angel3_serialize: ^4.0.0 angel3_serialize: ^4.0.0
io: ^1.0.0
test: ^1.17.4 test: ^1.17.4
collection: ^1.15.0
optional: ^6.0.0-nullsafety.2
dev_dependencies: dev_dependencies:
angel3_orm_generator: ^4.0.0-beta.1 angel3_orm_generator: ^4.0.0-beta.1
angel3_framework: ^4.0.0 angel3_framework: ^4.0.0
build_runner: ^2.0.1 build_runner: ^2.0.1
optional: ^6.0.0-nullsafety.2
pedantic: ^1.11.0 pedantic: ^1.11.0