diff --git a/angel_orm/CHANGELOG.md b/angel_orm/CHANGELOG.md index 48877583..a648fe2f 100644 --- a/angel_orm/CHANGELOG.md +++ b/angel_orm/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-dev.21 +* Add tableName to query + # 2.0.0-dev.20 * Join updates. diff --git a/angel_orm/example/main.dart b/angel_orm/example/main.dart index 7831bb03..c5c73be4 100644 --- a/angel_orm/example/main.dart +++ b/angel_orm/example/main.dart @@ -23,7 +23,7 @@ class _FakeExecutor extends QueryExecutor { @override Future> query( - String query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [returningFields]) async { var now = new DateTime.now(); print( diff --git a/angel_orm/lib/src/query.dart b/angel_orm/lib/src/query.dart index ae4c0a60..b9b18e69 100644 --- a/angel_orm/lib/src/query.dart +++ b/angel_orm/lib/src/query.dart @@ -13,6 +13,9 @@ abstract class QueryBase { /// Values to insert into a prepared statement. final Map substitutionValues = {}; + /// The table against which to execute this query. + String get tableName; + /// The list of fields returned by this query. /// /// If it's `null`, then this query will perform a `SELECT *`. @@ -32,7 +35,7 @@ abstract class QueryBase { Future> get(QueryExecutor executor) async { var sql = compile(Set()); return executor - .query(sql, substitutionValues) + .query(tableName, sql, substitutionValues) .then((it) => it.map(deserialize).toList()); } @@ -116,9 +119,6 @@ abstract class Query extends QueryBase { String _crossJoin, _groupBy; int _limit, _offset; - /// The table against which to execute this query. - String get tableName; - /// A reference to an abstract query builder. /// /// This is usually a generated class. @@ -320,15 +320,17 @@ abstract class Query extends QueryBase { if (_joins.isEmpty) { return executor - .query( - sql, substitutionValues, fields.map(adornWithTableName).toList()) + .query(tableName, sql, substitutionValues, + fields.map(adornWithTableName).toList()) .then((it) => it.map(deserialize).toList()); } else { return executor.transaction(() async { // TODO: Can this be done with just *one* query? var existing = await get(executor); //var sql = compile(preamble: 'SELECT $tableName.id', withFields: false); - return executor.query(sql, substitutionValues).then((_) => existing); + return executor + .query(tableName, sql, substitutionValues) + .then((_) => existing); }); } } @@ -348,7 +350,7 @@ abstract class Query extends QueryBase { var sql = compile(Set()); sql = 'WITH $tableName as ($insertion RETURNING $returning) ' + sql; return executor - .query(sql, substitutionValues) + .query(tableName, sql, substitutionValues) .then((it) => it.isEmpty ? null : deserialize(it.first)); } } @@ -370,7 +372,7 @@ abstract class Query extends QueryBase { sql = 'WITH $tableName as ($updateSql RETURNING $returning) ' + sql; return executor - .query(sql, substitutionValues) + .query(tableName, sql, substitutionValues) .then((it) => it.map(deserialize).toList()); } } @@ -504,10 +506,17 @@ abstract class QueryWhere { /// Represents the `UNION` of two subqueries. class Union extends QueryBase { + /// The subject(s) of this binary operation. final QueryBase left, right; + + /// Whether this is a `UNION ALL` operation. final bool all; - Union(this.left, this.right, {this.all: false}) { + @override + final String tableName; + + Union(this.left, this.right, {this.all: false, String tableName}) + : this.tableName = tableName ?? left.tableName { substitutionValues ..addAll(left.substitutionValues) ..addAll(right.substitutionValues); @@ -598,9 +607,11 @@ class JoinOn { abstract class QueryExecutor { const QueryExecutor(); + /// Executes a single query. Future> query( - String query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [List returningFields]); + /// Begins a database transaction. Future transaction(FutureOr f()); } diff --git a/angel_orm/pubspec.yaml b/angel_orm/pubspec.yaml index a905dbae..22efdc03 100644 --- a/angel_orm/pubspec.yaml +++ b/angel_orm/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm -version: 2.0.0-dev.20 +version: 2.0.0-dev.21 description: Runtime support for Angel's ORM. Includes base classes for queries. author: Tobe O homepage: https://github.com/angel-dart/orm diff --git a/angel_orm_generator/example/main.dart b/angel_orm_generator/example/main.dart index 7831bb03..c5c73be4 100644 --- a/angel_orm_generator/example/main.dart +++ b/angel_orm_generator/example/main.dart @@ -23,7 +23,7 @@ class _FakeExecutor extends QueryExecutor { @override Future> query( - String query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [returningFields]) async { var now = new DateTime.now(); print( diff --git a/angel_orm_generator/test/common.dart b/angel_orm_generator/test/common.dart index 2ed9b4a5..eea77a49 100644 --- a/angel_orm_generator/test/common.dart +++ b/angel_orm_generator/test/common.dart @@ -24,7 +24,7 @@ class PostgresExecutor extends QueryExecutor { @override Future> query( - String query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [List returningFields]) { if (returningFields != null) { var fields = returningFields.join(', '); diff --git a/angel_orm_mysql/lib/angel_orm_mysql.dart b/angel_orm_mysql/lib/angel_orm_mysql.dart new file mode 100644 index 00000000..e69de29b diff --git a/angel_orm_mysql/mono_pkg.yaml b/angel_orm_mysql/mono_pkg.yaml new file mode 100644 index 00000000..e69de29b diff --git a/angel_orm_mysql/pubspec.yaml b/angel_orm_mysql/pubspec.yaml new file mode 100644 index 00000000..64db6b14 --- /dev/null +++ b/angel_orm_mysql/pubspec.yaml @@ -0,0 +1,14 @@ +name: angel_orm_mysql +version: 1.0.0-dev +description: MySQL support for Angel's ORM. Includes functionality for querying and transactions. +author: Tobe O +homepage: https://github.com/angel-dart/orm +environment: + sdk: '>=2.0.0-dev.1.2 <3.0.0' +dependencies: + angel_orm: ^2.0.0-dev + logging: ^0.11.0 + pool: ^1.0.0 + sqljocky5: ^2.0.0 +dev_dependencies: + test: ^1.0.0 \ No newline at end of file diff --git a/angel_orm_postgres/CHANGELOG.md b/angel_orm_postgres/CHANGELOG.md index 4b9731aa..76a9858b 100644 --- a/angel_orm_postgres/CHANGELOG.md +++ b/angel_orm_postgres/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.0.0-dev.3 +* Support for `tableName`. + # 1.0.0-dev.2 * Add optional logging. diff --git a/angel_orm_postgres/example/main.dart b/angel_orm_postgres/example/main.dart index dc62f987..4f24f1df 100644 --- a/angel_orm_postgres/example/main.dart +++ b/angel_orm_postgres/example/main.dart @@ -7,6 +7,6 @@ main() async { return new PostgreSQLConnection('localhost', 5432, 'angel_orm_test'); }); - var rows = await executor.query('SELECT * FROM users', {}); + var rows = await executor.query('users', 'SELECT * FROM users', {}); print(rows); } diff --git a/angel_orm_postgres/lib/angel_orm_postgres.dart b/angel_orm_postgres/lib/angel_orm_postgres.dart index 53ce6b03..a4fd269a 100644 --- a/angel_orm_postgres/lib/angel_orm_postgres.dart +++ b/angel_orm_postgres/lib/angel_orm_postgres.dart @@ -21,7 +21,7 @@ class PostgreSQLExecutor extends QueryExecutor { @override Future> query( - String query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [List returningFields]) { if (returningFields != null) { var fields = returningFields.join(', '); @@ -104,11 +104,12 @@ class PostgreSQLExecutorPool extends QueryExecutor { @override Future> query( - String query, Map substitutionValues, + String tableName, String query, Map substitutionValues, [List returningFields]) { return _pool.withResource(() async { var executor = await _next(); - return executor.query(query, substitutionValues, returningFields); + return executor.query( + tableName, query, substitutionValues, returningFields); }); } diff --git a/angel_orm_postgres/pubspec.yaml b/angel_orm_postgres/pubspec.yaml index 7b6d0772..1cc33a1e 100644 --- a/angel_orm_postgres/pubspec.yaml +++ b/angel_orm_postgres/pubspec.yaml @@ -1,5 +1,5 @@ name: angel_orm_postgres -version: 1.0.0-dev.2 +version: 1.0.0-dev.3 description: PostgreSQL support for Angel's ORM. Includes functionality for querying and transactions. author: Tobe O homepage: https://github.com/angel-dart/orm