Updated ORM generator

This commit is contained in:
thomashii 2022-02-07 20:42:32 +08:00
parent f28ba22bb4
commit f9b07b2477
28 changed files with 108 additions and 76 deletions

View file

@ -1,5 +1,10 @@
# Change Log
## 4.0.4
* Updated README
* Removed deprecated
## 4.0.3
* Updated README

View file

@ -10,5 +10,5 @@ A database migration framework built for Angel3 ORM.
## Supported database
* PostgreSQL version 10 or later
* MySQL 8.0 or later
* MariaDB 10.2.1 or later
* MySQL 8.0.x
* MariaDB 10.2.x

View file

@ -19,8 +19,8 @@ abstract class Table {
MigrationColumn date(String name) => declare(name, ColumnType.date);
@deprecated
MigrationColumn dateTime(String name) => timeStamp(name, timezone: true);
//@deprecated
//MigrationColumn dateTime(String name) => timeStamp(name, timezone: true);
MigrationColumn timeStamp(String name, {bool timezone = false}) {
if (timezone != true) return declare(name, ColumnType.timeStamp);

View file

@ -1,11 +1,14 @@
name: angel3_migration
version: 4.0.3
version: 4.1.0
description: Database migration runtime for Angel3 ORM. Use this package to define schemas.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_migration
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel3_orm: ^4.0.0
angel3_orm: ^4.1.0
dev_dependencies:
lints: ^1.0.0
dependency_overrides:
angel3_orm:
path: ../angel_orm

View file

@ -1,5 +1,9 @@
# Change Log
## 4.1.2
* Updated README
## 4.1.1
* Updated README

View file

@ -10,5 +10,5 @@ Command-line based database migration runner for Angel3 ORM.
Supported database:
* PostgreSQL version 10 or later
* MySQL 8.0 or later
* MariaDB 10.2.1 or later
* MySQL 8.0.x
* MariaDB 10.2.x

View file

@ -1,13 +1,13 @@
name: angel3_migration_runner
version: 4.1.1
version: 4.1.2
description: Command-line based database migration runner for Angel3's ORM.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_migration_runner
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel3_migration: ^4.0.0
angel3_orm: ^4.0.0
angel3_migration: ^4.1.0
angel3_orm: ^4.1.0
args: ^2.1.0
charcode: ^1.2.0
postgres: ^2.4.0
@ -15,4 +15,8 @@ dependencies:
logging: ^1.0.0
dev_dependencies:
lints: ^1.0.0
dependency_overrides:
angel3_orm:
path: ../angel_orm
angel3_migration:
path: ../angel_migration

View file

@ -1,5 +1,10 @@
# Change Log
## 4.1.0
* Added `MySQLDialect` to handle MySQL database specific features
* Updated `insert` and `update` query to support database without writable CTE
## 4.0.6
* Fixed multiple `orderBy` error

View file

@ -10,6 +10,7 @@ Runtime support for Angel3 ORM. Includes a clean, database-agnostic query builde
## Supported database
* PostgreSQL version 10, 11, 12, 13 and 14
* MySQL 8.0 or later
* MariaDB 10.2.x
* MySQL 8.0.x
For documentation about the ORM, see [Developer Guide](https://angel3-docs.dukefirehawk.com/guides/orm)

View file

@ -343,7 +343,7 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
Future<List<T>> delete(QueryExecutor executor) {
var sql = compile({}, preamble: 'DELETE', withFields: false);
//_log.fine("Delete Query = $sql");
//_log.warning("Delete Query = $sql");
if (_joins.isEmpty) {
return executor
@ -379,14 +379,20 @@ abstract class Query<T, Where extends QueryWhere> extends QueryBase<T> {
var returning = fields.map(adornWithTableName).join(', ');
sql = 'WITH $tableName as ($insertion RETURNING $returning) ' + sql;
} else if (executor.dialect is MySQLDialect) {
// Default to using 'id' as primary key in model
if (fields.contains("id")) {
returningSql = '$sql where $tableName.id=?';
} else {
var returningSelect = values?.compileInsertSelect(this, tableName);
returningSql = '$sql where $returningSelect';
}
sql = '$insertion';
} else {
throw ArgumentError("Unsupported database dialect.");
}
_log.warning("Insert Query = $sql");
//_log.warning("Insert Query = $sql");
return executor
.query(tableName, sql, substitutionValues,

View file

@ -1,5 +1,5 @@
name: angel3_orm
version: 4.0.6
version: 4.1.0
description: Runtime support for Angel3 ORM. Includes base classes for queries.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm

View file

@ -1,5 +1,10 @@
# Change Log
## 5.0.0
* Updated `analyzer` to version 3.x
* Updated min SDK to 2.14.x
## 4.3.0
* Added `where.raw()`

View file

@ -21,8 +21,12 @@ class _FakeExecutor extends QueryExecutor {
@override
Future<List<List>> query(
String tableName, String? query, Map<String, dynamic> substitutionValues,
[returningFields = const []]) async {
String tableName,
String? query,
Map<String, dynamic> substitutionValues, {
String returningQuery = '',
List<String> returningFields = const [],
}) async {
var now = DateTime.now();
print(
'_FakeExecutor received query: $query and values: $substitutionValues');
@ -35,6 +39,10 @@ class _FakeExecutor extends QueryExecutor {
Future<T> transaction<T>(FutureOr<T> Function(QueryExecutor) f) {
throw UnsupportedError('Transactions are not supported.');
}
@override
// TODO: implement dialect
Dialect get dialect => PostgreSQLDialect();
}
@orm

View file

@ -110,7 +110,8 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
var type = ctx.columns[field.name]?.type;
if (type == null) continue;
if (floatTypes.contains(type)) {
args[name] = literalString('text');
//args[name] = literalString('text');
args[name] = literalString('char');
}
}

View file

@ -1,16 +1,16 @@
name: angel3_orm_generator
version: 4.3.0
version: 5.0.0
description: Code generators for Angel3 ORM. Generates query builder classes.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_generator
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.14.0 <3.0.0'
dependencies:
analyzer: ^2.0.0
analyzer: ^3.0.0
angel3_model: ^3.0.0
angel3_serialize: ^4.0.0
angel3_orm: ^4.0.0
angel3_serialize_generator: ^4.0.0
angel3_orm: ^4.1.0
angel3_serialize_generator: ^5.0.0
inflection3: ^0.5.3+1
build: ^2.0.1
build_config: ^1.0.0
@ -25,7 +25,7 @@ dependencies:
optional: ^6.0.0
dev_dependencies:
angel3_framework: ^4.2.0
angel3_migration: ^4.0.0
angel3_migration: ^4.1.0
build_runner: ^2.0.1
postgres: ^2.4.0
test: ^1.17.3
@ -35,4 +35,6 @@ dependency_overrides:
path: ../angel_orm
angel3_migration:
path: ../angel_migration
angel3_serialize_generator:
path: ../../serialize/angel_serialize_generator

View file

@ -90,9 +90,9 @@ class MySqlExecutor extends QueryExecutor {
var params = substitutionValues.values.toList();
logger?.warning('Query: $query');
logger?.warning('Values: $params');
logger?.warning('Returning Query: $returningQuery');
//logger?.warning('Query: $query');
//logger?.warning('Values: $params');
//logger?.warning('Returning Query: $returningQuery');
if (returningQuery.isNotEmpty) {
// Handle insert, update and delete
@ -101,12 +101,12 @@ class MySqlExecutor extends QueryExecutor {
var result = await _connection.query(query, params);
query = returningQuery;
logger?.warning('Result.insertId: ${result.insertId}');
// No primary key
//logger?.warning('Result.insertId: ${result.insertId}');
// Has primary key
//if (result.insertId != 0) {
// params = [result.insertId];
//}
if (returningQuery.endsWith('.id=?')) {
params = [result.insertId];
}
} else if (query.startsWith("UPDATE")) {
await _connection.query(query, params);
query = returningQuery;

View file

@ -11,11 +11,8 @@ dependencies:
mysql1: ^0.19.0
optional: ^6.0.0
dev_dependencies:
angel3_migration: ^4.0.0
angel3_orm_generator: ^4.0.0
build_runner: ^2.0.0
test: ^1.17.0
angel3_orm_test: ^3.0.0
test: ^1.17.0
lints: ^1.0.0
dependency_overrides:
angel3_orm_test:

View file

@ -20,8 +20,10 @@ void main() {
group('enumAndNested',
() => enumAndNestedTests(my(['has_car']), close: closeMy));
group('hasMany', () => hasManyTests(my(['tree', 'fruit']), close: closeMy));
group('hasMap', () => hasMapTests(my(['has_map']), close: closeMy));
group('hasOne', () => hasOneTests(my(['leg', 'foot']), close: closeMy));
// NOTE: MySQL/MariaDB do not support jsonb data type
//group('hasMap', () => hasMapTests(my(['has_map']), close: closeMy));
// NOTE: mysql1 driver do not support CAST();
//group('hasOne', () => hasOneTests(my(['leg', 'foot']), close: closeMy));
group(
'manyToMany',
() =>

View file

@ -16,6 +16,6 @@ void main() async {
belongsToTests(my(['author', 'book']), close: closeMy);
//edgeCaseTests(my(['unorthodox', 'weird_join', 'song', 'numba']),
// close: closeMy);
//hasOneTests(my(['leg', 'foot']), close: closeMy);
//standaloneTests(my(['car']), close: closeMy);
}

View file

@ -203,7 +203,7 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
@override
Map<String, String> get casts {
return {'n_toes': 'text'};
return {'n_toes': 'char'};
}
@override

View file

@ -77,7 +77,7 @@ void standaloneTests(FutureOr<QueryExecutor> Function() createExecutor,
var sportsCars = CarQuery()..where!.familyFriendly.isFalse;
cars = await sportsCars.get(executor!);
//print(cars.map((c) => c.toJson()));
print(cars.map((c) => c.toJson()));
var car = cars.first;
expect(car.make, ferrari!.make);

View file

@ -1,5 +1,14 @@
# Change Log
## 5.0.0
* Updated `analyzer` to version 3.x
* Updated min SDK to 2.14.x
## 4.1.1
* Removed deprecated
## 4.1.0
* Updated README

View file

@ -87,8 +87,6 @@ class Serializable {
const Serializable(
{this.serializers = const [Serializers.map, Serializers.json],
this.autoSnakeCaseNames = true,
// ignore: deprecated_member_use_from_same_package
//@deprecated this.autoIdAndDateFields = true,
this.includeAnnotations = const []});
/// A list of enabled serialization modes.
@ -99,10 +97,6 @@ class Serializable {
/// Overrides the setting in `SerializerGenerator`.
final bool autoSnakeCaseNames;
/// Overrides the setting in `JsonModelGenerator`.
//@deprecated
//final bool autoIdAndDateFields;
/// A list of constant members to affix to the generated class.
final List includeAnnotations;
}
@ -130,20 +124,3 @@ abstract class Serializers {
/// Generate a TypeScript definition file (`.d.ts`) for use on the client-side.
static const int typescript = 2;
}
/*
@deprecated
class DefaultValue {
final value;
const DefaultValue(this.value);
}
@deprecated
/// Prefer [SerializableField] instead.
class Alias {
final String name;
const Alias(this.name);
}
*/

View file

@ -1,8 +1,8 @@
name: angel3_serialize
version: 4.1.0
version: 4.1.1
description: Static annotations powering Angel3 model serialization. Combine with angel3_serialize_generator for flexible modeling.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/serialize/angel_serialize
repository: https://github.com/dukefirehawk/angel/tree/master/packages/serialize/angel_serialize
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:

View file

@ -1,5 +1,10 @@
# Change Log
## 5.0.0
* Updated `analyzer` to version 3.x
* Updated min SDK to 2.14.x
## 4.3.0
* Updated to use `package:belatuk_code_buffer`

View file

@ -7,7 +7,6 @@ import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:angel3_model/angel3_model.dart';
import 'package:angel3_serialize/angel3_serialize.dart';
import 'package:build/build.dart';
import 'package:belatuk_code_buffer/belatuk_code_buffer.dart';

View file

@ -5,7 +5,6 @@ import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:angel3_serialize/angel3_serialize.dart';
import 'package:build/build.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:recase/recase.dart';
import 'package:source_gen/source_gen.dart';

View file

@ -1,12 +1,12 @@
name: angel3_serialize_generator
version: 4.3.0
version: 5.0.0
description: Angel3 model serialization generators, designed for use with Angel. Combine with angel_serialize for flexible modeling.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/serialize/angel_serialize_generator
repository: https://github.com/dukefirehawk/angel/tree/master/packages/serialize/angel_serialize_generator
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.14.0 <3.0.0'
dependencies:
analyzer: ^2.0.0
analyzer: ^3.0.0
angel3_model: ^3.0.0
angel3_serialize: ^4.1.0
belatuk_code_buffer: ^3.0.0