Updated to support postgresql 3 driver

This commit is contained in:
thomashii 2024-02-12 12:31:33 +08:00
parent ae3544396c
commit fe44b0f60b
6 changed files with 44 additions and 25 deletions

View file

@ -1,20 +1,27 @@
import 'dart:io';
import 'package:angel3_migration/angel3_migration.dart'; import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_migration_runner/angel3_migration_runner.dart'; import 'package:angel3_migration_runner/angel3_migration_runner.dart';
import 'package:angel3_migration_runner/postgres.dart'; import 'package:angel3_migration_runner/postgres.dart';
import 'package:angel3_migration_runner/mysql.dart';
import 'package:angel3_orm/angel3_orm.dart'; import 'package:angel3_orm/angel3_orm.dart';
import 'package:postgres/postgres.dart'; import 'package:postgres/postgres.dart';
import 'package:mysql_client/mysql_client.dart';
import 'todo.dart'; import 'todo.dart';
void main(List<String> args) async { void main(List<String> args) async {
var host = Platform.environment['DB_HOST'] ?? 'localhost';
var database = Platform.environment['DB_NAME'] ?? 'demo';
var username = Platform.environment['DB_USERNAME'] ?? 'demouser';
var password = Platform.environment['DB_PASSWORD'] ?? 'demo123';
print("$host $database $username $password");
Connection conn = await Connection.open(Endpoint( Connection conn = await Connection.open(Endpoint(
host: 'localhost', host: host,
port: 5432, port: 5432,
database: 'demo', database: database,
username: 'demouser', username: username,
password: 'demo123')); password: password));
var postgresqlMigrationRunner = PostgresMigrationRunner( var postgresqlMigrationRunner = PostgresMigrationRunner(
conn, conn,
@ -25,12 +32,13 @@ void main(List<String> args) async {
], ],
); );
/*
var mySQLConn = await MySQLConnection.createConnection( var mySQLConn = await MySQLConnection.createConnection(
host: "localhost", host: host,
port: 3306, port: 3306,
databaseName: "orm_test", databaseName: database,
userName: "test", userName: username,
password: "Test123*", password: password,
secure: false); secure: false);
// ignore: unused_local_variable // ignore: unused_local_variable
@ -42,6 +50,7 @@ void main(List<String> args) async {
FooMigration(), FooMigration(),
], ],
); );
*/
runMigrations(postgresqlMigrationRunner, args); runMigrations(postgresqlMigrationRunner, args);
} }

View file

@ -392,7 +392,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
throw ArgumentError("Unsupported database dialect."); throw ArgumentError("Unsupported database dialect.");
} }
//_log.warning("Insert Query = $sql"); _log.fine("Insert Query = $sql");
return executor return executor
.query(tableName, sql, substitutionValues, .query(tableName, sql, substitutionValues,

View file

@ -5,7 +5,7 @@ import 'package:postgres/postgres.dart';
void main() async { void main() async {
var executor = PostgreSqlPoolExecutor(Pool.withEndpoints([ var executor = PostgreSqlPoolExecutor(Pool.withEndpoints([
Endpoint( Endpoint(
host: 'localhost', host: Platform.environment['POSTGRES_HOSTNAME'] ?? 'localhost',
port: 5432, port: 5432,
database: Platform.environment['POSTGRES_DB'] ?? 'orm_test', database: Platform.environment['POSTGRES_DB'] ?? 'orm_test',
username: Platform.environment['POSTGRES_USERNAME'] ?? 'test', username: Platform.environment['POSTGRES_USERNAME'] ?? 'test',

View file

@ -16,18 +16,18 @@ dev_dependencies:
angel3_orm_test: ^8.0.0 angel3_orm_test: ^8.0.0
test: ^1.24.0 test: ^1.24.0
lints: ^3.0.0 lints: ^3.0.0
# dependency_overrides: dependency_overrides:
# angel3_serialize: # angel3_serialize:
# path: ../../serialize/angel_serialize # path: ../../serialize/angel_serialize
# angel3_serialize_generator: # angel3_serialize_generator:
# path: ../../serialize/angel_serialize_generator # path: ../../serialize/angel_serialize_generator
# angel3_model: # angel3_model:
# path: ../../model # path: ../../model
# angel3_orm_test: angel3_orm_test:
# path: ../angel_orm_test path: ../angel_orm_test
# angel3_orm_generator: # angel3_orm_generator:
# path: ../angel_orm_generator # path: ../angel_orm_generator
# angel3_orm: # angel3_orm:
# path: ../angel_orm # path: ../angel_orm
# angel3_migration: angel3_migration:
# path: ../angel_migration path: ../angel_migration

View file

@ -20,13 +20,19 @@ Future<void> closePg(QueryExecutor executor) async {
} }
Future<PostgreSqlExecutor> connectToPostgres(Iterable<String> schemas) async { Future<PostgreSqlExecutor> connectToPostgres(Iterable<String> schemas) async {
// postgres://kfayrlbi:OAaEE39zOMLEPfH4DDgHbGNVsQtNdHu7@heffalump.db.elephantsql.com/kfayrlbi var host = Platform.environment['POSTGRES_HOST'] ?? 'localhost';
var conn = await Connection.open(Endpoint( var database = Platform.environment['POSTGRES_NAME'] ?? 'orm_test';
host: 'localhost', var username = Platform.environment['POSTGRES_USERNAME'] ?? 'test';
port: 5432, var password = Platform.environment['POSTGRES_PASSWORD'] ?? 'test123';
database: Platform.environment['POSTGRES_DB'] ?? 'orm_test',
username: Platform.environment['POSTGRES_USERNAME'] ?? 'test', var conn = await Connection.open(
password: Platform.environment['POSTGRES_PASSWORD'] ?? 'test123')); Endpoint(
host: host,
port: 5432,
database: database,
username: username,
password: password),
settings: ConnectionSettings(sslMode: SslMode.disable));
// Run sql to create the tables // Run sql to create the tables
for (var s in schemas) { for (var s in schemas) {

View file

@ -24,7 +24,11 @@ void customExprTests(FutureOr<QueryExecutor> Function() createExecutor,
}); });
}); });
tearDown(() => close!(executor)); tearDown(() {
if (close != null) {
close(executor);
}
});
test('fetches correct result', () async { test('fetches correct result', () async {
expect(numbersModel.two, 2); expect(numbersModel.two, 2);