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_runner/angel3_migration_runner.dart';
import 'package:angel3_migration_runner/postgres.dart';
import 'package:angel3_migration_runner/mysql.dart';
import 'package:angel3_orm/angel3_orm.dart';
import 'package:postgres/postgres.dart';
import 'package:mysql_client/mysql_client.dart';
import 'todo.dart';
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(
host: 'localhost',
host: host,
port: 5432,
database: 'demo',
username: 'demouser',
password: 'demo123'));
database: database,
username: username,
password: password));
var postgresqlMigrationRunner = PostgresMigrationRunner(
conn,
@ -25,12 +32,13 @@ void main(List<String> args) async {
],
);
/*
var mySQLConn = await MySQLConnection.createConnection(
host: "localhost",
host: host,
port: 3306,
databaseName: "orm_test",
userName: "test",
password: "Test123*",
databaseName: database,
userName: username,
password: password,
secure: false);
// ignore: unused_local_variable
@ -42,6 +50,7 @@ void main(List<String> args) async {
FooMigration(),
],
);
*/
runMigrations(postgresqlMigrationRunner, args);
}

View file

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

View file

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

View file

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

View file

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