diff --git a/angel_orm_generator/test/models/author.g.dart b/angel_orm_generator/test/models/author.g.dart deleted file mode 100644 index 98cb18cf..00000000 --- a/angel_orm_generator/test/models/author.g.dart +++ /dev/null @@ -1,52 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm.generator.models.author; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Author extends _Author { - @override - String id; - - @override - String name; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Author({this.id, this.name, this.createdAt, this.updatedAt}); - - factory Author.fromJson(Map data) { - return new Author( - id: data['id'], - name: data['name'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'name': name, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Author parse(Map map) => new Author.fromJson(map); - - Author clone() { - return new Author.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/author.migration.g.dart b/angel_orm_generator/test/models/author.migration.g.dart deleted file mode 100644 index e8fb5908..00000000 --- a/angel_orm_generator/test/models/author.migration.g.dart +++ /dev/null @@ -1,26 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class AuthorMigration extends Migration { - @override - up(Schema schema) { - schema.create('authors', (table) { - table.serial('id')..primaryKey(); - table.varchar('name', length: 255) - ..defaultsTo('Tobe Osakwe') - ..unique(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('authors'); - } -} diff --git a/angel_orm_generator/test/models/author.orm.g.dart b/angel_orm_generator/test/models/author.orm.g.dart deleted file mode 100644 index 686525d2..00000000 --- a/angel_orm_generator/test/models/author.orm.g.dart +++ /dev/null @@ -1,253 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'author.dart'; - -class AuthorQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final AuthorQueryWhere where = new AuthorQueryWhere(); - - void union(AuthorQuery query) { - _unions[query] = false; - } - - void unionAll(AuthorQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(AuthorQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, name, created_at, updated_at FROM "authors"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Author parseRow(List row) { - var result = new Author.fromJson({ - 'id': row[0].toString(), - 'name': row[1], - 'created_at': row[2], - 'updated_at': row[3] - }); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new AuthorQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {String name: 'Tobe Osakwe', DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "authors" SET ("name", "created_at", "updated_at") = (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + ' RETURNING "id", "name", "created_at", "updated_at";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "authors"') + - ' RETURNING "id", "name", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new AuthorQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {String name: 'Tobe Osakwe', - DateTime createdAt, - DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "authors" ("name", "created_at", "updated_at") VALUES (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "name", "created_at", "updated_at";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertAuthor( - PostgreSQLConnection connection, Author author) { - return AuthorQuery.insert(connection, - name: author.name, - createdAt: author.createdAt, - updatedAt: author.updatedAt); - } - - static Future updateAuthor( - PostgreSQLConnection connection, Author author) { - var query = new AuthorQuery(); - query.where.id.equals(int.parse(author.id)); - return query - .update(connection, - name: author.name, - createdAt: author.createdAt, - updatedAt: author.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new AuthorQuery().get(connection); -} - -class AuthorQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder name = new StringSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('authors.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('authors.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('authors.id ' + id.compile()); - } - if (name.hasValue) { - expressions.add('authors.name ' + name.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class AuthorFields { - static const id = 'id'; - - static const name = 'name'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/author.service.g.dart b/angel_orm_generator/test/models/author.service.g.dart deleted file mode 100644 index 24277a40..00000000 --- a/angel_orm_generator/test/models/author.service.g.dart +++ /dev/null @@ -1,150 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'author.dart'; -import 'author.orm.g.dart'; - -class AuthorService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - AuthorService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - AuthorQuery buildQuery(Map params) { - var query = new AuthorQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.name.equals(params['query']['name']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Author applyData(data) { - if (data is Author || data == null) { - return data; - } - if (data is Map) { - var query = new Author(); - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return AuthorQuery.insertAuthor(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return AuthorQuery.updateAuthor(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Author) { - query = data; - } - if (data is Map) { - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await AuthorQuery.updateAuthor(connection, query); - } -} diff --git a/angel_orm_generator/test/models/book.g.dart b/angel_orm_generator/test/models/book.g.dart deleted file mode 100644 index e1d33bf0..00000000 --- a/angel_orm_generator/test/models/book.g.dart +++ /dev/null @@ -1,72 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm.generator.models.book; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Book extends _Book { - @override - String id; - - @override - Author author; - - @override - int authorId; - - @override - String name; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Book( - {this.id, - this.author, - this.authorId, - this.name, - this.createdAt, - this.updatedAt}); - - factory Book.fromJson(Map data) { - return new Book( - id: data['id'], - author: data['author'] == null - ? null - : (data['author'] is Author - ? data['author'] - : new Author.fromJson(data['author'])), - authorId: data['author_id'], - name: data['name'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'author': author, - 'author_id': authorId, - 'name': name, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Book parse(Map map) => new Book.fromJson(map); - - Book clone() { - return new Book.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/book.migration.g.dart b/angel_orm_generator/test/models/book.migration.g.dart deleted file mode 100644 index 12ae1d13..00000000 --- a/angel_orm_generator/test/models/book.migration.g.dart +++ /dev/null @@ -1,25 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class BookMigration extends Migration { - @override - up(Schema schema) { - schema.create('books', (table) { - table.serial('id')..primaryKey(); - table.varchar('name'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('author_id').references('authors', 'id').onDeleteCascade(); - }); - } - - @override - down(Schema schema) { - schema.drop('books'); - } -} diff --git a/angel_orm_generator/test/models/book.orm.g.dart b/angel_orm_generator/test/models/book.orm.g.dart deleted file mode 100644 index 0c0cc41c..00000000 --- a/angel_orm_generator/test/models/book.orm.g.dart +++ /dev/null @@ -1,277 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'book.dart'; -import 'author.orm.g.dart'; - -class BookQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final BookQueryWhere where = new BookQueryWhere(); - - void union(BookQuery query) { - _unions[query] = false; - } - - void unionAll(BookQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('books.' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('books.' + key); - } - - void or(BookQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT books.id, books.name, books.created_at, books.updated_at, books.author_id, authors.id, authors.name, authors.created_at, authors.updated_at FROM "books"'); - if (prefix == null) { - buf.write(' LEFT OUTER JOIN authors ON books.author_id = authors.id'); - } - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Book parseRow(List row) { - var result = new Book.fromJson({ - 'id': row[0].toString(), - 'name': row[1], - 'created_at': row[2], - 'updated_at': row[3], - 'author_id': row[4] - }); - if (row.length > 5) { - result.author = AuthorQuery.parseRow([row[5], row[6], row[7], row[8]]); - } - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - parsed.author = await AuthorQuery.getOne(row[4], connection); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new BookQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {String name, DateTime createdAt, DateTime updatedAt, int authorId}) { - var buf = new StringBuffer( - 'UPDATE "books" SET ("name", "created_at", "updated_at", "author_id") = (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp), @authorId) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "name", "created_at", "updated_at", "author_id";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__, - 'authorId': authorId - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - parsed.author = await AuthorQuery.getOne(row[4], connection); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "books"') + - ' RETURNING "id", "name", "created_at", "updated_at", "author_id";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - parsed.author = await AuthorQuery.getOne(row[4], connection); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new BookQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {String name, - DateTime createdAt, - DateTime updatedAt, - int authorId}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "books" ("name", "created_at", "updated_at", "author_id") VALUES (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp), @authorId) RETURNING "id", "name", "created_at", "updated_at", "author_id";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__, - 'authorId': authorId - }); - var output = parseRow(result[0]); - output.author = await AuthorQuery.getOne(result[0][4], connection); - return output; - } - - static Future insertBook(PostgreSQLConnection connection, Book book, - {int authorId}) { - return BookQuery.insert(connection, - name: book.name, - createdAt: book.createdAt, - updatedAt: book.updatedAt, - authorId: authorId); - } - - static Future updateBook(PostgreSQLConnection connection, Book book) { - var query = new BookQuery(); - query.where.id.equals(int.parse(book.id)); - return query - .update(connection, - name: book.name, - createdAt: book.createdAt, - updatedAt: book.updatedAt, - authorId: int.parse(book.author.id)) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new BookQuery().get(connection); -} - -class BookQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder name = new StringSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('books.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('books.updated_at'); - - final NumericSqlExpressionBuilder authorId = - new NumericSqlExpressionBuilder(); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('books.id ' + id.compile()); - } - if (name.hasValue) { - expressions.add('books.name ' + name.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - if (authorId.hasValue) { - expressions.add('books.author_id ' + authorId.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class BookFields { - static const id = 'id'; - - static const name = 'name'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; - - static const authorId = 'author_id'; -} diff --git a/angel_orm_generator/test/models/book.service.g.dart b/angel_orm_generator/test/models/book.service.g.dart deleted file mode 100644 index 1305f40c..00000000 --- a/angel_orm_generator/test/models/book.service.g.dart +++ /dev/null @@ -1,157 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'book.dart'; -import 'book.orm.g.dart'; - -class BookService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - BookService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - BookQuery buildQuery(Map params) { - var query = new BookQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.name.equals(params['query']['name']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - query.where.authorId.equals(params['query']['author_id']); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Book applyData(data) { - if (data is Book || data == null) { - return data; - } - if (data is Map) { - var query = new Book(); - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - if (data.containsKey('author_id')) { - query.authorId = data['author_id']; - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return BookQuery.insertBook(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return BookQuery.updateBook(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Book) { - query = data; - } - if (data is Map) { - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - if (data.containsKey('author_id')) { - query.authorId = data['author_id']; - } - } - return await BookQuery.updateBook(connection, query); - } -} diff --git a/angel_orm_generator/test/models/car.g.dart b/angel_orm_generator/test/models/car.g.dart deleted file mode 100644 index 61664ed6..00000000 --- a/angel_orm_generator/test/models/car.g.dart +++ /dev/null @@ -1,78 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm.generator.models.car; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Car extends _Car { - @override - String id; - - @override - String make; - - @override - String description; - - @override - bool familyFriendly; - - @override - DateTime recalledAt; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Car( - {this.id, - this.make, - this.description, - this.familyFriendly, - this.recalledAt, - this.createdAt, - this.updatedAt}); - - factory Car.fromJson(Map data) { - return new Car( - id: data['id'], - make: data['make'], - description: data['description'], - familyFriendly: data['family_friendly'], - recalledAt: data['recalled_at'] is DateTime - ? data['recalled_at'] - : (data['recalled_at'] is String - ? DateTime.parse(data['recalled_at']) - : null), - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'make': make, - 'description': description, - 'family_friendly': familyFriendly, - 'recalled_at': recalledAt == null ? null : recalledAt.toIso8601String(), - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Car parse(Map map) => new Car.fromJson(map); - - Car clone() { - return new Car.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/car.migration.g.dart b/angel_orm_generator/test/models/car.migration.g.dart deleted file mode 100644 index 4714b5c5..00000000 --- a/angel_orm_generator/test/models/car.migration.g.dart +++ /dev/null @@ -1,27 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class CarMigration extends Migration { - @override - up(Schema schema) { - schema.create('cars', (table) { - table.serial('id')..primaryKey(); - table.varchar('make'); - table.varchar('description'); - table.boolean('family_friendly'); - table.timeStamp('recalled_at'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('cars'); - } -} diff --git a/angel_orm_generator/test/models/car.orm.g.dart b/angel_orm_generator/test/models/car.orm.g.dart deleted file mode 100644 index 074df007..00000000 --- a/angel_orm_generator/test/models/car.orm.g.dart +++ /dev/null @@ -1,299 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'car.dart'; - -class CarQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final CarQueryWhere where = new CarQueryWhere(); - - void union(CarQuery query) { - _unions[query] = false; - } - - void unionAll(CarQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(CarQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, make, description, family_friendly, recalled_at, created_at, updated_at FROM "cars"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Car parseRow(List row) { - var result = new Car.fromJson({ - 'id': row[0].toString(), - 'make': row[1], - 'description': row[2], - 'family_friendly': row[3], - 'recalled_at': row[4], - 'created_at': row[5], - 'updated_at': row[6] - }); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new CarQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {String make, - String description, - bool familyFriendly, - DateTime recalledAt, - DateTime createdAt, - DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "cars" SET ("make", "description", "family_friendly", "recalled_at", "created_at", "updated_at") = (@make, @description, @familyFriendly, CAST (@recalledAt AS timestamp), CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "make", "description", "family_friendly", "recalled_at", "created_at", "updated_at";', - substitutionValues: { - 'make': make, - 'description': description, - 'familyFriendly': familyFriendly, - 'recalledAt': recalledAt, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "cars"') + - ' RETURNING "id", "make", "description", "family_friendly", "recalled_at", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new CarQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {String make, - String description, - bool familyFriendly, - DateTime recalledAt, - DateTime createdAt, - DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "cars" ("make", "description", "family_friendly", "recalled_at", "created_at", "updated_at") VALUES (@make, @description, @familyFriendly, CAST (@recalledAt AS timestamp), CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "make", "description", "family_friendly", "recalled_at", "created_at", "updated_at";', - substitutionValues: { - 'make': make, - 'description': description, - 'familyFriendly': familyFriendly, - 'recalledAt': recalledAt, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertCar(PostgreSQLConnection connection, Car car) { - return CarQuery.insert(connection, - make: car.make, - description: car.description, - familyFriendly: car.familyFriendly, - recalledAt: car.recalledAt, - createdAt: car.createdAt, - updatedAt: car.updatedAt); - } - - static Future updateCar(PostgreSQLConnection connection, Car car) { - var query = new CarQuery(); - query.where.id.equals(int.parse(car.id)); - return query - .update(connection, - make: car.make, - description: car.description, - familyFriendly: car.familyFriendly, - recalledAt: car.recalledAt, - createdAt: car.createdAt, - updatedAt: car.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new CarQuery().get(connection); -} - -class CarQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder make = new StringSqlExpressionBuilder(); - - final StringSqlExpressionBuilder description = - new StringSqlExpressionBuilder(); - - final BooleanSqlExpressionBuilder familyFriendly = - new BooleanSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder recalledAt = - new DateTimeSqlExpressionBuilder('cars.recalled_at'); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('cars.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('cars.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('cars.id ' + id.compile()); - } - if (make.hasValue) { - expressions.add('cars.make ' + make.compile()); - } - if (description.hasValue) { - expressions.add('cars.description ' + description.compile()); - } - if (familyFriendly.hasValue) { - expressions.add('cars.family_friendly ' + familyFriendly.compile()); - } - if (recalledAt.hasValue) { - expressions.add(recalledAt.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class CarFields { - static const id = 'id'; - - static const make = 'make'; - - static const description = 'description'; - - static const familyFriendly = 'family_friendly'; - - static const recalledAt = 'recalled_at'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/car.service.g.dart b/angel_orm_generator/test/models/car.service.g.dart deleted file mode 100644 index a04e4062..00000000 --- a/angel_orm_generator/test/models/car.service.g.dart +++ /dev/null @@ -1,189 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'car.dart'; -import 'car.orm.g.dart'; - -class CarService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - CarService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - CarQuery buildQuery(Map params) { - var query = new CarQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.make.equals(params['query']['make']); - query.where.description.equals(params['query']['description']); - query.where.familyFriendly.equals(params['query']['family_friendly']); - query.where.recalledAt.equals(params['query']['recalled_at'] is String - ? DateTime.parse(params['query']['recalled_at']) - : params['query']['recalled_at'] != null - ? params['query']['recalled_at'] is String - ? DateTime.parse(params['query']['recalled_at']) - : params['query']['recalled_at'] - : new DateTime.now()); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Car applyData(data) { - if (data is Car || data == null) { - return data; - } - if (data is Map) { - var query = new Car(); - if (data.containsKey('make')) { - query.make = data['make']; - } - if (data.containsKey('description')) { - query.description = data['description']; - } - if (data.containsKey('family_friendly')) { - query.familyFriendly = data['family_friendly']; - } - if (data.containsKey('recalled_at')) { - query.recalledAt = data['recalled_at'] is String - ? DateTime.parse(data['recalled_at']) - : data['recalled_at'] != null - ? data['recalled_at'] is String - ? DateTime.parse(data['recalled_at']) - : data['recalled_at'] - : new DateTime.now(); - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return CarQuery.insertCar(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return CarQuery.updateCar(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Car) { - query = data; - } - if (data is Map) { - if (data.containsKey('make')) { - query.make = data['make']; - } - if (data.containsKey('description')) { - query.description = data['description']; - } - if (data.containsKey('family_friendly')) { - query.familyFriendly = data['family_friendly']; - } - if (data.containsKey('recalled_at')) { - query.recalledAt = data['recalled_at'] is String - ? DateTime.parse(data['recalled_at']) - : data['recalled_at'] != null - ? data['recalled_at'] is String - ? DateTime.parse(data['recalled_at']) - : data['recalled_at'] - : new DateTime.now(); - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await CarQuery.updateCar(connection, query); - } -} diff --git a/angel_orm_generator/test/models/customer.g.dart b/angel_orm_generator/test/models/customer.g.dart deleted file mode 100644 index 0b3eb61a..00000000 --- a/angel_orm_generator/test/models/customer.g.dart +++ /dev/null @@ -1,47 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.customer; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Customer extends _Customer { - @override - String id; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Customer({this.id, this.createdAt, this.updatedAt}); - - factory Customer.fromJson(Map data) { - return new Customer( - id: data['id'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Customer parse(Map map) => new Customer.fromJson(map); - - Customer clone() { - return new Customer.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/customer.migration.g.dart b/angel_orm_generator/test/models/customer.migration.g.dart deleted file mode 100644 index 2aa60347..00000000 --- a/angel_orm_generator/test/models/customer.migration.g.dart +++ /dev/null @@ -1,23 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class CustomerMigration extends Migration { - @override - up(Schema schema) { - schema.create('customers', (table) { - table.serial('id')..primaryKey(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('customers'); - } -} diff --git a/angel_orm_generator/test/models/customer.orm.g.dart b/angel_orm_generator/test/models/customer.orm.g.dart deleted file mode 100644 index 9678e282..00000000 --- a/angel_orm_generator/test/models/customer.orm.g.dart +++ /dev/null @@ -1,234 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'customer.dart'; - -class CustomerQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final CustomerQueryWhere where = new CustomerQueryWhere(); - - void union(CustomerQuery query) { - _unions[query] = false; - } - - void unionAll(CustomerQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(CustomerQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, created_at, updated_at FROM "customers"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Customer parseRow(List row) { - var result = new Customer.fromJson( - {'id': row[0].toString(), 'created_at': row[1], 'updated_at': row[2]}); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new CustomerQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "customers" SET ("created_at", "updated_at") = (CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + ' RETURNING "id", "created_at", "updated_at";', - substitutionValues: { - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "customers"') + - ' RETURNING "id", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new CustomerQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {DateTime createdAt, DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "customers" ("created_at", "updated_at") VALUES (CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "created_at", "updated_at";', - substitutionValues: { - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertCustomer( - PostgreSQLConnection connection, Customer customer) { - return CustomerQuery.insert(connection, - createdAt: customer.createdAt, updatedAt: customer.updatedAt); - } - - static Future updateCustomer( - PostgreSQLConnection connection, Customer customer) { - var query = new CustomerQuery(); - query.where.id.equals(int.parse(customer.id)); - return query - .update(connection, - createdAt: customer.createdAt, updatedAt: customer.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new CustomerQuery().get(connection); -} - -class CustomerQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('customers.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('customers.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('customers.id ' + id.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class CustomerFields { - static const id = 'id'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/customer.service.g.dart b/angel_orm_generator/test/models/customer.service.g.dart deleted file mode 100644 index 9dacce0f..00000000 --- a/angel_orm_generator/test/models/customer.service.g.dart +++ /dev/null @@ -1,143 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'customer.dart'; -import 'customer.orm.g.dart'; - -class CustomerService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - CustomerService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - CustomerQuery buildQuery(Map params) { - var query = new CustomerQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Customer applyData(data) { - if (data is Customer || data == null) { - return data; - } - if (data is Map) { - var query = new Customer(); - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return CustomerQuery.insertCustomer(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return CustomerQuery.updateCustomer(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Customer) { - query = data; - } - if (data is Map) { - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await CustomerQuery.updateCustomer(connection, query); - } -} diff --git a/angel_orm_generator/test/models/foot.g.dart b/angel_orm_generator/test/models/foot.g.dart deleted file mode 100644 index 62a2b605..00000000 --- a/angel_orm_generator/test/models/foot.g.dart +++ /dev/null @@ -1,57 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.foot; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Foot extends _Foot { - @override - String id; - - @override - int legId; - - @override - int nToes; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Foot({this.id, this.legId, this.nToes, this.createdAt, this.updatedAt}); - - factory Foot.fromJson(Map data) { - return new Foot( - id: data['id'], - legId: data['leg_id'], - nToes: data['n_toes'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'leg_id': legId, - 'n_toes': nToes, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Foot parse(Map map) => new Foot.fromJson(map); - - Foot clone() { - return new Foot.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/foot.migration.g.dart b/angel_orm_generator/test/models/foot.migration.g.dart deleted file mode 100644 index 0e365597..00000000 --- a/angel_orm_generator/test/models/foot.migration.g.dart +++ /dev/null @@ -1,25 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class FootMigration extends Migration { - @override - up(Schema schema) { - schema.create('foots', (table) { - table.serial('id')..primaryKey(); - table.integer('leg_id'); - table.integer('n_toes'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('foots'); - } -} diff --git a/angel_orm_generator/test/models/foot.orm.g.dart b/angel_orm_generator/test/models/foot.orm.g.dart deleted file mode 100644 index 62ef4f39..00000000 --- a/angel_orm_generator/test/models/foot.orm.g.dart +++ /dev/null @@ -1,264 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'foot.dart'; - -class FootQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final FootQueryWhere where = new FootQueryWhere(); - - void union(FootQuery query) { - _unions[query] = false; - } - - void unionAll(FootQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(FootQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, leg_id, n_toes, created_at, updated_at FROM "foots"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Foot parseRow(List row) { - var result = new Foot.fromJson({ - 'id': row[0].toString(), - 'leg_id': row[1], - 'n_toes': row[2], - 'created_at': row[3], - 'updated_at': row[4] - }); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new FootQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {int legId, int nToes, DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "foots" SET ("leg_id", "n_toes", "created_at", "updated_at") = (@legId, @nToes, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "leg_id", "n_toes", "created_at", "updated_at";', - substitutionValues: { - 'legId': legId, - 'nToes': nToes, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "foots"') + - ' RETURNING "id", "leg_id", "n_toes", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new FootQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {int legId, int nToes, DateTime createdAt, DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "foots" ("leg_id", "n_toes", "created_at", "updated_at") VALUES (@legId, @nToes, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "leg_id", "n_toes", "created_at", "updated_at";', - substitutionValues: { - 'legId': legId, - 'nToes': nToes, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertFoot(PostgreSQLConnection connection, Foot foot) { - return FootQuery.insert(connection, - legId: foot.legId, - nToes: foot.nToes, - createdAt: foot.createdAt, - updatedAt: foot.updatedAt); - } - - static Future updateFoot(PostgreSQLConnection connection, Foot foot) { - var query = new FootQuery(); - query.where.id.equals(int.parse(foot.id)); - return query - .update(connection, - legId: foot.legId, - nToes: foot.nToes, - createdAt: foot.createdAt, - updatedAt: foot.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new FootQuery().get(connection); -} - -class FootQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final NumericSqlExpressionBuilder legId = - new NumericSqlExpressionBuilder(); - - final NumericSqlExpressionBuilder nToes = - new NumericSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('foots.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('foots.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('foots.id ' + id.compile()); - } - if (legId.hasValue) { - expressions.add('foots.leg_id ' + legId.compile()); - } - if (nToes.hasValue) { - expressions.add('foots.n_toes ' + nToes.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class FootFields { - static const id = 'id'; - - static const legId = 'leg_id'; - - static const nToes = 'n_toes'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/foot.service.g.dart b/angel_orm_generator/test/models/foot.service.g.dart deleted file mode 100644 index 2f1f3954..00000000 --- a/angel_orm_generator/test/models/foot.service.g.dart +++ /dev/null @@ -1,157 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'foot.dart'; -import 'foot.orm.g.dart'; - -class FootService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - FootService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - FootQuery buildQuery(Map params) { - var query = new FootQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.legId.equals(params['query']['leg_id']); - query.where.nToes.equals(params['query']['n_toes']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Foot applyData(data) { - if (data is Foot || data == null) { - return data; - } - if (data is Map) { - var query = new Foot(); - if (data.containsKey('leg_id')) { - query.legId = data['leg_id']; - } - if (data.containsKey('n_toes')) { - query.nToes = data['n_toes']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return FootQuery.insertFoot(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return FootQuery.updateFoot(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Foot) { - query = data; - } - if (data is Map) { - if (data.containsKey('leg_id')) { - query.legId = data['leg_id']; - } - if (data.containsKey('n_toes')) { - query.nToes = data['n_toes']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await FootQuery.updateFoot(connection, query); - } -} diff --git a/angel_orm_generator/test/models/fruit.g.dart b/angel_orm_generator/test/models/fruit.g.dart deleted file mode 100644 index f7121069..00000000 --- a/angel_orm_generator/test/models/fruit.g.dart +++ /dev/null @@ -1,58 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.fruit; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Fruit extends _Fruit { - @override - String id; - - @override - int treeId; - - @override - String commonName; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Fruit( - {this.id, this.treeId, this.commonName, this.createdAt, this.updatedAt}); - - factory Fruit.fromJson(Map data) { - return new Fruit( - id: data['id'], - treeId: data['tree_id'], - commonName: data['common_name'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'tree_id': treeId, - 'common_name': commonName, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Fruit parse(Map map) => new Fruit.fromJson(map); - - Fruit clone() { - return new Fruit.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/fruit.migration.g.dart b/angel_orm_generator/test/models/fruit.migration.g.dart deleted file mode 100644 index a5021b2b..00000000 --- a/angel_orm_generator/test/models/fruit.migration.g.dart +++ /dev/null @@ -1,25 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class FruitMigration extends Migration { - @override - up(Schema schema) { - schema.create('fruits', (table) { - table.serial('id')..primaryKey(); - table.integer('tree_id'); - table.varchar('common_name'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('fruits'); - } -} diff --git a/angel_orm_generator/test/models/fruit.orm.g.dart b/angel_orm_generator/test/models/fruit.orm.g.dart deleted file mode 100644 index 43ade1ea..00000000 --- a/angel_orm_generator/test/models/fruit.orm.g.dart +++ /dev/null @@ -1,269 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'fruit.dart'; - -class FruitQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final FruitQueryWhere where = new FruitQueryWhere(); - - void union(FruitQuery query) { - _unions[query] = false; - } - - void unionAll(FruitQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(FruitQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, tree_id, common_name, created_at, updated_at FROM "fruits"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Fruit parseRow(List row) { - var result = new Fruit.fromJson({ - 'id': row[0].toString(), - 'tree_id': row[1], - 'common_name': row[2], - 'created_at': row[3], - 'updated_at': row[4] - }); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new FruitQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {int treeId, String commonName, DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "fruits" SET ("tree_id", "common_name", "created_at", "updated_at") = (@treeId, @commonName, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "tree_id", "common_name", "created_at", "updated_at";', - substitutionValues: { - 'treeId': treeId, - 'commonName': commonName, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "fruits"') + - ' RETURNING "id", "tree_id", "common_name", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new FruitQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {int treeId, - String commonName, - DateTime createdAt, - DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "fruits" ("tree_id", "common_name", "created_at", "updated_at") VALUES (@treeId, @commonName, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "tree_id", "common_name", "created_at", "updated_at";', - substitutionValues: { - 'treeId': treeId, - 'commonName': commonName, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertFruit( - PostgreSQLConnection connection, Fruit fruit) { - return FruitQuery.insert(connection, - treeId: fruit.treeId, - commonName: fruit.commonName, - createdAt: fruit.createdAt, - updatedAt: fruit.updatedAt); - } - - static Future updateFruit( - PostgreSQLConnection connection, Fruit fruit) { - var query = new FruitQuery(); - query.where.id.equals(int.parse(fruit.id)); - return query - .update(connection, - treeId: fruit.treeId, - commonName: fruit.commonName, - createdAt: fruit.createdAt, - updatedAt: fruit.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new FruitQuery().get(connection); -} - -class FruitQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final NumericSqlExpressionBuilder treeId = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder commonName = - new StringSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('fruits.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('fruits.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('fruits.id ' + id.compile()); - } - if (treeId.hasValue) { - expressions.add('fruits.tree_id ' + treeId.compile()); - } - if (commonName.hasValue) { - expressions.add('fruits.common_name ' + commonName.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class FruitFields { - static const id = 'id'; - - static const treeId = 'tree_id'; - - static const commonName = 'common_name'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/fruit.service.g.dart b/angel_orm_generator/test/models/fruit.service.g.dart deleted file mode 100644 index 620724c8..00000000 --- a/angel_orm_generator/test/models/fruit.service.g.dart +++ /dev/null @@ -1,157 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'fruit.dart'; -import 'fruit.orm.g.dart'; - -class FruitService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - FruitService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - FruitQuery buildQuery(Map params) { - var query = new FruitQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.treeId.equals(params['query']['tree_id']); - query.where.commonName.equals(params['query']['common_name']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Fruit applyData(data) { - if (data is Fruit || data == null) { - return data; - } - if (data is Map) { - var query = new Fruit(); - if (data.containsKey('tree_id')) { - query.treeId = data['tree_id']; - } - if (data.containsKey('common_name')) { - query.commonName = data['common_name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return FruitQuery.insertFruit(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return FruitQuery.updateFruit(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Fruit) { - query = data; - } - if (data is Map) { - if (data.containsKey('tree_id')) { - query.treeId = data['tree_id']; - } - if (data.containsKey('common_name')) { - query.commonName = data['common_name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await FruitQuery.updateFruit(connection, query); - } -} diff --git a/angel_orm_generator/test/models/leg.g.dart b/angel_orm_generator/test/models/leg.g.dart deleted file mode 100644 index 62c0a33d..00000000 --- a/angel_orm_generator/test/models/leg.g.dart +++ /dev/null @@ -1,61 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.leg; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Leg extends _Leg { - @override - String id; - - @override - Foot foot; - - @override - String name; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Leg({this.id, this.foot, this.name, this.createdAt, this.updatedAt}); - - factory Leg.fromJson(Map data) { - return new Leg( - id: data['id'], - foot: data['foot'] == null - ? null - : (data['foot'] is Foot - ? data['foot'] - : new Foot.fromJson(data['foot'])), - name: data['name'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'foot': foot, - 'name': name, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Leg parse(Map map) => new Leg.fromJson(map); - - Leg clone() { - return new Leg.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/leg.migration.g.dart b/angel_orm_generator/test/models/leg.migration.g.dart deleted file mode 100644 index 32a0ab1a..00000000 --- a/angel_orm_generator/test/models/leg.migration.g.dart +++ /dev/null @@ -1,24 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class LegMigration extends Migration { - @override - up(Schema schema) { - schema.create('legs', (table) { - table.serial('id')..primaryKey(); - table.varchar('name'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('legs'); - } -} diff --git a/angel_orm_generator/test/models/leg.orm.g.dart b/angel_orm_generator/test/models/leg.orm.g.dart deleted file mode 100644 index 5b6c4865..00000000 --- a/angel_orm_generator/test/models/leg.orm.g.dart +++ /dev/null @@ -1,267 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'leg.dart'; -import 'foot.orm.g.dart'; - -class LegQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final LegQueryWhere where = new LegQueryWhere(); - - void union(LegQuery query) { - _unions[query] = false; - } - - void unionAll(LegQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('legs.' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('legs.' + key); - } - - void or(LegQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT legs.id, legs.name, legs.created_at, legs.updated_at, foots.id, foots.leg_id, foots.n_toes, foots.created_at, foots.updated_at FROM "legs"'); - if (prefix == null) { - buf.write(' LEFT OUTER JOIN foots ON legs.id = foots.leg_id'); - } - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Leg parseRow(List row) { - var result = new Leg.fromJson({ - 'id': row[0].toString(), - 'name': row[1], - 'created_at': row[2], - 'updated_at': row[3] - }); - if (row.length > 4) { - result.foot = - FootQuery.parseRow([row[4], row[5], row[6], row[7], row[8]]); - } - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var footQuery = new FootQuery(); - footQuery.where.id.equals(row[0]); - parsed.foot = - await footQuery.get(connection).first.catchError((_) => null); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new LegQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {String name, DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "legs" SET ("name", "created_at", "updated_at") = (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + ' RETURNING "id", "name", "created_at", "updated_at";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var footQuery = new FootQuery(); - footQuery.where.id.equals(row[0]); - parsed.foot = - await footQuery.get(connection).first.catchError((_) => null); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "legs"') + - ' RETURNING "id", "name", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var footQuery = new FootQuery(); - footQuery.where.id.equals(row[0]); - parsed.foot = - await footQuery.get(connection).first.catchError((_) => null); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new LegQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {String name, DateTime createdAt, DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "legs" ("name", "created_at", "updated_at") VALUES (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "name", "created_at", "updated_at";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - var footQuery = new FootQuery(); - footQuery.where.id.equals(result[0][0]); - output.foot = await footQuery.get(connection).first.catchError((_) => null); - return output; - } - - static Future insertLeg(PostgreSQLConnection connection, Leg leg) { - return LegQuery.insert(connection, - name: leg.name, createdAt: leg.createdAt, updatedAt: leg.updatedAt); - } - - static Future updateLeg(PostgreSQLConnection connection, Leg leg) { - var query = new LegQuery(); - query.where.id.equals(int.parse(leg.id)); - return query - .update(connection, - name: leg.name, createdAt: leg.createdAt, updatedAt: leg.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new LegQuery().get(connection); -} - -class LegQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder name = new StringSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('legs.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('legs.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('legs.id ' + id.compile()); - } - if (name.hasValue) { - expressions.add('legs.name ' + name.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class LegFields { - static const id = 'id'; - - static const name = 'name'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/leg.service.g.dart b/angel_orm_generator/test/models/leg.service.g.dart deleted file mode 100644 index df156b18..00000000 --- a/angel_orm_generator/test/models/leg.service.g.dart +++ /dev/null @@ -1,150 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'leg.dart'; -import 'leg.orm.g.dart'; - -class LegService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - LegService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - LegQuery buildQuery(Map params) { - var query = new LegQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.name.equals(params['query']['name']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Leg applyData(data) { - if (data is Leg || data == null) { - return data; - } - if (data is Map) { - var query = new Leg(); - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return LegQuery.insertLeg(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return LegQuery.updateLeg(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Leg) { - query = data; - } - if (data is Map) { - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await LegQuery.updateLeg(connection, query); - } -} diff --git a/angel_orm_generator/test/models/order.g.dart b/angel_orm_generator/test/models/order.g.dart deleted file mode 100644 index aea06634..00000000 --- a/angel_orm_generator/test/models/order.g.dart +++ /dev/null @@ -1,78 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.order; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Order extends _Order { - @override - String id; - - @override - int customerId; - - @override - int employeeId; - - @override - DateTime orderDate; - - @override - int shipperId; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Order( - {this.id, - this.customerId, - this.employeeId, - this.orderDate, - this.shipperId, - this.createdAt, - this.updatedAt}); - - factory Order.fromJson(Map data) { - return new Order( - id: data['id'], - customerId: data['customer_id'], - employeeId: data['employee_id'], - orderDate: data['order_date'] is DateTime - ? data['order_date'] - : (data['order_date'] is String - ? DateTime.parse(data['order_date']) - : null), - shipperId: data['shipper_id'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'customer_id': customerId, - 'employee_id': employeeId, - 'order_date': orderDate == null ? null : orderDate.toIso8601String(), - 'shipper_id': shipperId, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Order parse(Map map) => new Order.fromJson(map); - - Order clone() { - return new Order.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/order.migration.g.dart b/angel_orm_generator/test/models/order.migration.g.dart deleted file mode 100644 index 53a26a44..00000000 --- a/angel_orm_generator/test/models/order.migration.g.dart +++ /dev/null @@ -1,27 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class OrderMigration extends Migration { - @override - up(Schema schema) { - schema.create('orders', (table) { - table.serial('id')..primaryKey(); - table.integer('customer_id'); - table.integer('employee_id'); - table.timeStamp('order_date'); - table.integer('shipper_id'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('orders'); - } -} diff --git a/angel_orm_generator/test/models/order.orm.g.dart b/angel_orm_generator/test/models/order.orm.g.dart deleted file mode 100644 index 476c800e..00000000 --- a/angel_orm_generator/test/models/order.orm.g.dart +++ /dev/null @@ -1,304 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'order.dart'; - -class OrderQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final OrderQueryWhere where = new OrderQueryWhere(); - - void union(OrderQuery query) { - _unions[query] = false; - } - - void unionAll(OrderQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(OrderQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, customer_id, employee_id, order_date, shipper_id, created_at, updated_at FROM "orders"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Order parseRow(List row) { - var result = new Order.fromJson({ - 'id': row[0].toString(), - 'customer_id': row[1], - 'employee_id': row[2], - 'order_date': row[3], - 'shipper_id': row[4], - 'created_at': row[5], - 'updated_at': row[6] - }); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new OrderQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {int customerId, - int employeeId, - DateTime orderDate, - int shipperId, - DateTime createdAt, - DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "orders" SET ("customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at") = (@customerId, @employeeId, CAST (@orderDate AS timestamp), @shipperId, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at";', - substitutionValues: { - 'customerId': customerId, - 'employeeId': employeeId, - 'orderDate': orderDate, - 'shipperId': shipperId, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "orders"') + - ' RETURNING "id", "customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new OrderQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {int customerId, - int employeeId, - DateTime orderDate, - int shipperId, - DateTime createdAt, - DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "orders" ("customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at") VALUES (@customerId, @employeeId, CAST (@orderDate AS timestamp), @shipperId, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at";', - substitutionValues: { - 'customerId': customerId, - 'employeeId': employeeId, - 'orderDate': orderDate, - 'shipperId': shipperId, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertOrder( - PostgreSQLConnection connection, Order order) { - return OrderQuery.insert(connection, - customerId: order.customerId, - employeeId: order.employeeId, - orderDate: order.orderDate, - shipperId: order.shipperId, - createdAt: order.createdAt, - updatedAt: order.updatedAt); - } - - static Future updateOrder( - PostgreSQLConnection connection, Order order) { - var query = new OrderQuery(); - query.where.id.equals(int.parse(order.id)); - return query - .update(connection, - customerId: order.customerId, - employeeId: order.employeeId, - orderDate: order.orderDate, - shipperId: order.shipperId, - createdAt: order.createdAt, - updatedAt: order.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new OrderQuery().get(connection); - - static joinCustomers(PostgreSQLConnection connection) {} -} - -class OrderQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final NumericSqlExpressionBuilder customerId = - new NumericSqlExpressionBuilder(); - - final NumericSqlExpressionBuilder employeeId = - new NumericSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder orderDate = - new DateTimeSqlExpressionBuilder('orders.order_date'); - - final NumericSqlExpressionBuilder shipperId = - new NumericSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('orders.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('orders.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('orders.id ' + id.compile()); - } - if (customerId.hasValue) { - expressions.add('orders.customer_id ' + customerId.compile()); - } - if (employeeId.hasValue) { - expressions.add('orders.employee_id ' + employeeId.compile()); - } - if (orderDate.hasValue) { - expressions.add(orderDate.compile()); - } - if (shipperId.hasValue) { - expressions.add('orders.shipper_id ' + shipperId.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class OrderFields { - static const id = 'id'; - - static const customerId = 'customer_id'; - - static const employeeId = 'employee_id'; - - static const orderDate = 'order_date'; - - static const shipperId = 'shipper_id'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/order.service.g.dart b/angel_orm_generator/test/models/order.service.g.dart deleted file mode 100644 index 8ee3d5bb..00000000 --- a/angel_orm_generator/test/models/order.service.g.dart +++ /dev/null @@ -1,189 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'order.dart'; -import 'order.orm.g.dart'; - -class OrderService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - OrderService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - OrderQuery buildQuery(Map params) { - var query = new OrderQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.customerId.equals(params['query']['customer_id']); - query.where.employeeId.equals(params['query']['employee_id']); - query.where.orderDate.equals(params['query']['order_date'] is String - ? DateTime.parse(params['query']['order_date']) - : params['query']['order_date'] != null - ? params['query']['order_date'] is String - ? DateTime.parse(params['query']['order_date']) - : params['query']['order_date'] - : new DateTime.now()); - query.where.shipperId.equals(params['query']['shipper_id']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Order applyData(data) { - if (data is Order || data == null) { - return data; - } - if (data is Map) { - var query = new Order(); - if (data.containsKey('customer_id')) { - query.customerId = data['customer_id']; - } - if (data.containsKey('employee_id')) { - query.employeeId = data['employee_id']; - } - if (data.containsKey('order_date')) { - query.orderDate = data['order_date'] is String - ? DateTime.parse(data['order_date']) - : data['order_date'] != null - ? data['order_date'] is String - ? DateTime.parse(data['order_date']) - : data['order_date'] - : new DateTime.now(); - } - if (data.containsKey('shipper_id')) { - query.shipperId = data['shipper_id']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return OrderQuery.insertOrder(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return OrderQuery.updateOrder(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Order) { - query = data; - } - if (data is Map) { - if (data.containsKey('customer_id')) { - query.customerId = data['customer_id']; - } - if (data.containsKey('employee_id')) { - query.employeeId = data['employee_id']; - } - if (data.containsKey('order_date')) { - query.orderDate = data['order_date'] is String - ? DateTime.parse(data['order_date']) - : data['order_date'] != null - ? data['order_date'] is String - ? DateTime.parse(data['order_date']) - : data['order_date'] - : new DateTime.now(); - } - if (data.containsKey('shipper_id')) { - query.shipperId = data['shipper_id']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await OrderQuery.updateOrder(connection, query); - } -} diff --git a/angel_orm_generator/test/models/role.g.dart b/angel_orm_generator/test/models/role.g.dart deleted file mode 100644 index 17d3bdc0..00000000 --- a/angel_orm_generator/test/models/role.g.dart +++ /dev/null @@ -1,52 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.role; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Role extends _Role { - @override - String id; - - @override - String name; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Role({this.id, this.name, this.createdAt, this.updatedAt}); - - factory Role.fromJson(Map data) { - return new Role( - id: data['id'], - name: data['name'], - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'name': name, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Role parse(Map map) => new Role.fromJson(map); - - Role clone() { - return new Role.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/role.migration.g.dart b/angel_orm_generator/test/models/role.migration.g.dart deleted file mode 100644 index 3eeb6492..00000000 --- a/angel_orm_generator/test/models/role.migration.g.dart +++ /dev/null @@ -1,24 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class RoleMigration extends Migration { - @override - up(Schema schema) { - schema.create('roles', (table) { - table.serial('id')..primaryKey(); - table.varchar('name'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('roles'); - } -} diff --git a/angel_orm_generator/test/models/role.orm.g.dart b/angel_orm_generator/test/models/role.orm.g.dart deleted file mode 100644 index 9a0486ec..00000000 --- a/angel_orm_generator/test/models/role.orm.g.dart +++ /dev/null @@ -1,247 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'role.dart'; - -class RoleQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final RoleQueryWhere where = new RoleQueryWhere(); - - void union(RoleQuery query) { - _unions[query] = false; - } - - void unionAll(RoleQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('' + key); - } - - void or(RoleQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT id, name, created_at, updated_at FROM "roles"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Role parseRow(List row) { - var result = new Role.fromJson({ - 'id': row[0].toString(), - 'name': row[1], - 'created_at': row[2], - 'updated_at': row[3] - }); - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new RoleQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {String name, DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "roles" SET ("name", "created_at", "updated_at") = (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + ' RETURNING "id", "name", "created_at", "updated_at";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "roles"') + - ' RETURNING "id", "name", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new RoleQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {String name, DateTime createdAt, DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "roles" ("name", "created_at", "updated_at") VALUES (@name, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "name", "created_at", "updated_at";', - substitutionValues: { - 'name': name, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - return output; - } - - static Future insertRole(PostgreSQLConnection connection, Role role) { - return RoleQuery.insert(connection, - name: role.name, createdAt: role.createdAt, updatedAt: role.updatedAt); - } - - static Future updateRole(PostgreSQLConnection connection, Role role) { - var query = new RoleQuery(); - query.where.id.equals(int.parse(role.id)); - return query - .update(connection, - name: role.name, - createdAt: role.createdAt, - updatedAt: role.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new RoleQuery().get(connection); -} - -class RoleQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder name = new StringSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('roles.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('roles.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('roles.id ' + id.compile()); - } - if (name.hasValue) { - expressions.add('roles.name ' + name.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class RoleFields { - static const id = 'id'; - - static const name = 'name'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/role.service.g.dart b/angel_orm_generator/test/models/role.service.g.dart deleted file mode 100644 index 255bf763..00000000 --- a/angel_orm_generator/test/models/role.service.g.dart +++ /dev/null @@ -1,150 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'role.dart'; -import 'role.orm.g.dart'; - -class RoleService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - RoleService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - RoleQuery buildQuery(Map params) { - var query = new RoleQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.name.equals(params['query']['name']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Role applyData(data) { - if (data is Role || data == null) { - return data; - } - if (data is Map) { - var query = new Role(); - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return RoleQuery.insertRole(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return RoleQuery.updateRole(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Role) { - query = data; - } - if (data is Map) { - if (data.containsKey('name')) { - query.name = data['name']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await RoleQuery.updateRole(connection, query); - } -} diff --git a/angel_orm_generator/test/models/tree.g.dart b/angel_orm_generator/test/models/tree.g.dart deleted file mode 100644 index d74a52b2..00000000 --- a/angel_orm_generator/test/models/tree.g.dart +++ /dev/null @@ -1,62 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.tree; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class Tree extends _Tree { - @override - String id; - - @override - int rings; - - @override - List fruits; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - Tree({this.id, this.rings, this.fruits, this.createdAt, this.updatedAt}); - - factory Tree.fromJson(Map data) { - return new Tree( - id: data['id'], - rings: data['rings'], - fruits: data['fruits'] is List - ? data['fruits'] - .map((x) => - x == null ? null : (x is Fruit ? x : new Fruit.fromJson(x))) - .toList() - : null, - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'rings': rings, - 'fruits': fruits, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static Tree parse(Map map) => new Tree.fromJson(map); - - Tree clone() { - return new Tree.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/tree.migration.g.dart b/angel_orm_generator/test/models/tree.migration.g.dart deleted file mode 100644 index c0feec10..00000000 --- a/angel_orm_generator/test/models/tree.migration.g.dart +++ /dev/null @@ -1,25 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; -import 'package:angel_orm/angel_orm.dart'; - -class TreeMigration extends Migration { - @override - up(Schema schema) { - schema.create('trees', (table) { - table.serial('id')..primaryKey(); - table.declare('rings', new ColumnType('smallint'))..unique(); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - }); - } - - @override - down(Schema schema) { - schema.drop('trees'); - } -} diff --git a/angel_orm_generator/test/models/tree.orm.g.dart b/angel_orm_generator/test/models/tree.orm.g.dart deleted file mode 100644 index b21951cd..00000000 --- a/angel_orm_generator/test/models/tree.orm.g.dart +++ /dev/null @@ -1,272 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'tree.dart'; -import 'fruit.orm.g.dart'; - -class TreeQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final TreeQueryWhere where = new TreeQueryWhere(); - - void union(TreeQuery query) { - _unions[query] = false; - } - - void unionAll(TreeQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('trees.' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('trees.' + key); - } - - void or(TreeQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT trees.id, trees.rings, trees.created_at, trees.updated_at FROM "trees"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static Tree parseRow(List row) { - var result = new Tree.fromJson({ - 'id': row[0].toString(), - 'rings': row[1], - 'created_at': row[2], - 'updated_at': row[3] - }); - if (row.length > 4) { - result.fruits = - FruitQuery.parseRow([row[4], row[5], row[6], row[7], row[8]]); - } - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var fruitQuery = new FruitQuery(); - fruitQuery.where.treeId.equals(row[0]); - parsed.fruits = - await fruitQuery.get(connection).toList().catchError((_) => []); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new TreeQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {int rings, DateTime createdAt, DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "trees" SET ("rings", "created_at", "updated_at") = (@rings, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "rings", "created_at", "updated_at";', - substitutionValues: { - 'rings': rings, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var fruitQuery = new FruitQuery(); - fruitQuery.where.treeId.equals(row[0]); - parsed.fruits = - await fruitQuery.get(connection).toList().catchError((_) => []); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "trees"') + - ' RETURNING "id", "rings", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var fruitQuery = new FruitQuery(); - fruitQuery.where.treeId.equals(row[0]); - parsed.fruits = - await fruitQuery.get(connection).toList().catchError((_) => []); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new TreeQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {int rings, DateTime createdAt, DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "trees" ("rings", "created_at", "updated_at") VALUES (@rings, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "rings", "created_at", "updated_at";', - substitutionValues: { - 'rings': rings, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - var fruitQuery = new FruitQuery(); - fruitQuery.where.treeId.equals(result[0][0]); - output.fruits = - await fruitQuery.get(connection).toList().catchError((_) => []); - return output; - } - - static Future insertTree(PostgreSQLConnection connection, Tree tree) { - return TreeQuery.insert(connection, - rings: tree.rings, - createdAt: tree.createdAt, - updatedAt: tree.updatedAt); - } - - static Future updateTree(PostgreSQLConnection connection, Tree tree) { - var query = new TreeQuery(); - query.where.id.equals(int.parse(tree.id)); - return query - .update(connection, - rings: tree.rings, - createdAt: tree.createdAt, - updatedAt: tree.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new TreeQuery().get(connection); -} - -class TreeQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final NumericSqlExpressionBuilder rings = - new NumericSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('trees.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('trees.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('trees.id ' + id.compile()); - } - if (rings.hasValue) { - expressions.add('trees.rings ' + rings.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class TreeFields { - static const id = 'id'; - - static const rings = 'rings'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/tree.service.g.dart b/angel_orm_generator/test/models/tree.service.g.dart deleted file mode 100644 index a3926d2d..00000000 --- a/angel_orm_generator/test/models/tree.service.g.dart +++ /dev/null @@ -1,150 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'tree.dart'; -import 'tree.orm.g.dart'; - -class TreeService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - TreeService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - TreeQuery buildQuery(Map params) { - var query = new TreeQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.rings.equals(params['query']['rings']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - Tree applyData(data) { - if (data is Tree || data == null) { - return data; - } - if (data is Map) { - var query = new Tree(); - if (data.containsKey('rings')) { - query.rings = data['rings']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return TreeQuery.insertTree(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return TreeQuery.updateTree(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is Tree) { - query = data; - } - if (data is Map) { - if (data.containsKey('rings')) { - query.rings = data['rings']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await TreeQuery.updateTree(connection, query); - } -} diff --git a/angel_orm_generator/test/models/user.g.dart b/angel_orm_generator/test/models/user.g.dart deleted file mode 100644 index 123216bd..00000000 --- a/angel_orm_generator/test/models/user.g.dart +++ /dev/null @@ -1,79 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of angel_orm_generator.test.models.user; - -// ************************************************************************** -// Generator: JsonModelGenerator -// ************************************************************************** - -class User extends _User { - @override - String id; - - @override - String username; - - @override - String password; - - @override - String email; - - @override - List roles; - - @override - DateTime createdAt; - - @override - DateTime updatedAt; - - User( - {this.id, - this.username, - this.password, - this.email, - this.roles, - this.createdAt, - this.updatedAt}); - - factory User.fromJson(Map data) { - return new User( - id: data['id'], - username: data['username'], - password: data['password'], - email: data['email'], - roles: data['roles'] is List - ? data['roles'] - .map((x) => - x == null ? null : (x is Role ? x : new Role.fromJson(x))) - .toList() - : null, - createdAt: data['created_at'] is DateTime - ? data['created_at'] - : (data['created_at'] is String - ? DateTime.parse(data['created_at']) - : null), - updatedAt: data['updated_at'] is DateTime - ? data['updated_at'] - : (data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : null)); - } - - Map toJson() => { - 'id': id, - 'username': username, - 'password': password, - 'email': email, - 'roles': roles, - 'created_at': createdAt == null ? null : createdAt.toIso8601String(), - 'updated_at': updatedAt == null ? null : updatedAt.toIso8601String() - }; - - static User parse(Map map) => new User.fromJson(map); - - User clone() { - return new User.fromJson(toJson()); - } -} diff --git a/angel_orm_generator/test/models/user.migration.g.dart b/angel_orm_generator/test/models/user.migration.g.dart deleted file mode 100644 index c3654957..00000000 --- a/angel_orm_generator/test/models/user.migration.g.dart +++ /dev/null @@ -1,27 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: MigrationGenerator -// ************************************************************************** - -import 'package:angel_migration/angel_migration.dart'; - -class UserMigration extends Migration { - @override - up(Schema schema) { - schema.create('users', (table) { - table.serial('id')..primaryKey(); - table.varchar('username'); - table.varchar('password'); - table.varchar('email'); - table.timeStamp('created_at'); - table.timeStamp('updated_at'); - table.integer('role_id').references('roles', 'id'); - }); - } - - @override - down(Schema schema) { - schema.drop('users'); - } -} diff --git a/angel_orm_generator/test/models/user.orm.g.dart b/angel_orm_generator/test/models/user.orm.g.dart deleted file mode 100644 index b074722d..00000000 --- a/angel_orm_generator/test/models/user.orm.g.dart +++ /dev/null @@ -1,299 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresOrmGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_orm/angel_orm.dart'; -import 'package:postgres/postgres.dart'; -import 'user.dart'; -import 'role.orm.g.dart'; - -class UserQuery { - final Map _unions = {}; - - String _sortKey; - - String _sortMode; - - int limit; - - int offset; - - final List _or = []; - - final UserQueryWhere where = new UserQueryWhere(); - - void union(UserQuery query) { - _unions[query] = false; - } - - void unionAll(UserQuery query) { - _unions[query] = true; - } - - void sortDescending(String key) { - _sortMode = 'Descending'; - _sortKey = ('users.' + key); - } - - void sortAscending(String key) { - _sortMode = 'Ascending'; - _sortKey = ('users.' + key); - } - - void or(UserQueryWhere selector) { - _or.add(selector); - } - - String toSql([String prefix]) { - var buf = new StringBuffer(); - buf.write(prefix != null - ? prefix - : 'SELECT users.id, users.username, users.password, users.email, users.created_at, users.updated_at FROM "users"'); - if (prefix == null) {} - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(' ' + whereClause); - } - _or.forEach((x) { - var whereClause = x.toWhereClause(keyword: false); - if (whereClause != null) { - buf.write(' OR (' + whereClause + ')'); - } - }); - if (prefix == null) { - if (limit != null) { - buf.write(' LIMIT ' + limit.toString()); - } - if (offset != null) { - buf.write(' OFFSET ' + offset.toString()); - } - if (_sortMode == 'Descending') { - buf.write(' ORDER BY "' + _sortKey + '" DESC'); - } - if (_sortMode == 'Ascending') { - buf.write(' ORDER BY "' + _sortKey + '" ASC'); - } - _unions.forEach((query, all) { - buf.write(' UNION'); - if (all) { - buf.write(' ALL'); - } - buf.write(' ('); - var sql = query.toSql().replaceAll(';', ''); - buf.write(sql + ')'); - }); - buf.write(';'); - } - return buf.toString(); - } - - static User parseRow(List row) { - var result = new User.fromJson({ - 'id': row[0].toString(), - 'username': row[1], - 'password': row[2], - 'email': row[3], - 'created_at': row[4], - 'updated_at': row[5] - }); - if (row.length > 6) { - result.roles = RoleQuery.parseRow([row[6], row[7], row[8], row[9]]); - } - return result; - } - - Stream get(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection.query(toSql()).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var roleQuery = new RoleQuery(); - roleQuery.where.id.equals(row[6]); - parsed.roles.addAll(await roleQuery.get(connection).toList()); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future getOne(int id, PostgreSQLConnection connection) { - var query = new UserQuery(); - query.where.id.equals(id); - return query.get(connection).first.catchError((_) => null); - } - - Stream update(PostgreSQLConnection connection, - {String username, - String password, - String email, - DateTime createdAt, - DateTime updatedAt}) { - var buf = new StringBuffer( - 'UPDATE "users" SET ("username", "password", "email", "created_at", "updated_at") = (@username, @password, @email, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) '); - var whereClause = where.toWhereClause(); - if (whereClause != null) { - buf.write(whereClause); - } - var __ormNow__ = new DateTime.now(); - var ctrl = new StreamController(); - connection.query( - buf.toString() + - ' RETURNING "id", "username", "password", "email", "created_at", "updated_at";', - substitutionValues: { - 'username': username, - 'password': password, - 'email': email, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }).then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var roleQuery = new RoleQuery(); - roleQuery.where.id.equals(row[6]); - parsed.roles.addAll(await roleQuery.get(connection).toList()); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - Stream delete(PostgreSQLConnection connection) { - StreamController ctrl = new StreamController(); - connection - .query(toSql('DELETE FROM "users"') + - ' RETURNING "id", "username", "password", "email", "created_at", "updated_at";') - .then((rows) async { - var futures = rows.map((row) async { - var parsed = parseRow(row); - var roleQuery = new RoleQuery(); - roleQuery.where.id.equals(row[6]); - parsed.roles.addAll(await roleQuery.get(connection).toList()); - return parsed; - }); - var output = await Future.wait(futures); - output.forEach(ctrl.add); - ctrl.close(); - }).catchError(ctrl.addError); - return ctrl.stream; - } - - static Future deleteOne(int id, PostgreSQLConnection connection) { - var query = new UserQuery(); - query.where.id.equals(id); - return query.delete(connection).first; - } - - static Future insert(PostgreSQLConnection connection, - {String username, - String password, - String email, - DateTime createdAt, - DateTime updatedAt}) async { - var __ormNow__ = new DateTime.now(); - var result = await connection.query( - 'INSERT INTO "users" ("username", "password", "email", "created_at", "updated_at") VALUES (@username, @password, @email, CAST (@createdAt AS timestamp), CAST (@updatedAt AS timestamp)) RETURNING "id", "username", "password", "email", "created_at", "updated_at";', - substitutionValues: { - 'username': username, - 'password': password, - 'email': email, - 'createdAt': createdAt != null ? createdAt : __ormNow__, - 'updatedAt': updatedAt != null ? updatedAt : __ormNow__ - }); - var output = parseRow(result[0]); - var roleQuery = new RoleQuery(); - roleQuery.where.id.equals(result[0][6]); - output.roles.addAll(await roleQuery.get(connection).toList()); - return output; - } - - static Future insertUser(PostgreSQLConnection connection, User user, - {int roleId}) { - return UserQuery.insert(connection, - username: user.username, - password: user.password, - email: user.email, - createdAt: user.createdAt, - updatedAt: user.updatedAt); - } - - static Future updateUser(PostgreSQLConnection connection, User user) { - var query = new UserQuery(); - query.where.id.equals(int.parse(user.id)); - return query - .update(connection, - username: user.username, - password: user.password, - email: user.email, - createdAt: user.createdAt, - updatedAt: user.updatedAt) - .first; - } - - static Stream getAll(PostgreSQLConnection connection) => - new UserQuery().get(connection); -} - -class UserQueryWhere { - final NumericSqlExpressionBuilder id = - new NumericSqlExpressionBuilder(); - - final StringSqlExpressionBuilder username = new StringSqlExpressionBuilder(); - - final StringSqlExpressionBuilder password = new StringSqlExpressionBuilder(); - - final StringSqlExpressionBuilder email = new StringSqlExpressionBuilder(); - - final DateTimeSqlExpressionBuilder createdAt = - new DateTimeSqlExpressionBuilder('users.created_at'); - - final DateTimeSqlExpressionBuilder updatedAt = - new DateTimeSqlExpressionBuilder('users.updated_at'); - - String toWhereClause({bool keyword}) { - final List expressions = []; - if (id.hasValue) { - expressions.add('users.id ' + id.compile()); - } - if (username.hasValue) { - expressions.add('users.username ' + username.compile()); - } - if (password.hasValue) { - expressions.add('users.password ' + password.compile()); - } - if (email.hasValue) { - expressions.add('users.email ' + email.compile()); - } - if (createdAt.hasValue) { - expressions.add(createdAt.compile()); - } - if (updatedAt.hasValue) { - expressions.add(updatedAt.compile()); - } - return expressions.isEmpty - ? null - : ((keyword != false ? 'WHERE ' : '') + expressions.join(' AND ')); - } -} - -class UserFields { - static const id = 'id'; - - static const username = 'username'; - - static const password = 'password'; - - static const email = 'email'; - - static const createdAt = 'created_at'; - - static const updatedAt = 'updated_at'; -} diff --git a/angel_orm_generator/test/models/user.service.g.dart b/angel_orm_generator/test/models/user.service.g.dart deleted file mode 100644 index 40ea5e25..00000000 --- a/angel_orm_generator/test/models/user.service.g.dart +++ /dev/null @@ -1,164 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -// ************************************************************************** -// Generator: PostgresServiceGenerator -// ************************************************************************** - -import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:postgres/postgres.dart'; -import 'user.dart'; -import 'user.orm.g.dart'; - -class UserService extends Service { - final PostgreSQLConnection connection; - - final bool allowRemoveAll; - - final bool allowQuery; - - UserService(this.connection, - {this.allowRemoveAll: false, this.allowQuery: false}); - - UserQuery buildQuery(Map params) { - var query = new UserQuery(); - if (params['query'] is Map) { - query.where.id.equals(params['query']['id']); - query.where.username.equals(params['query']['username']); - query.where.password.equals(params['query']['password']); - query.where.email.equals(params['query']['email']); - query.where.createdAt.equals(params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] != null - ? params['query']['created_at'] is String - ? DateTime.parse(params['query']['created_at']) - : params['query']['created_at'] - : new DateTime.now()); - query.where.updatedAt.equals(params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] != null - ? params['query']['updated_at'] is String - ? DateTime.parse(params['query']['updated_at']) - : params['query']['updated_at'] - : new DateTime.now()); - } - return query; - } - - int toId(id) { - if (id is int) { - return id; - } else { - if (id == 'null' || id == null) { - return null; - } else { - return int.parse(id.toString()); - } - } - } - - User applyData(data) { - if (data is User || data == null) { - return data; - } - if (data is Map) { - var query = new User(); - if (data.containsKey('username')) { - query.username = data['username']; - } - if (data.containsKey('password')) { - query.password = data['password']; - } - if (data.containsKey('email')) { - query.email = data['email']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - return query; - } else - throw new AngelHttpException.badRequest(message: 'Invalid data.'); - } - - Future> index([Map params]) { - return buildQuery(params).get(connection).toList(); - } - - Future create(data, [Map params]) { - return UserQuery.insertUser(connection, applyData(data)); - } - - Future read(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.get(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future remove(id, [Map params]) { - var query = buildQuery(params); - query.where.id.equals(toId(id)); - return query.delete(connection).first.catchError((_) { - new AngelHttpException.notFound( - message: 'No record found for ID ' + id.toString()); - }); - } - - Future update(id, data, [Map params]) { - return UserQuery.updateUser(connection, applyData(data)); - } - - Future modify(id, data, [Map params]) async { - var query = await read(toId(id), params); - if (data is User) { - query = data; - } - if (data is Map) { - if (data.containsKey('username')) { - query.username = data['username']; - } - if (data.containsKey('password')) { - query.password = data['password']; - } - if (data.containsKey('email')) { - query.email = data['email']; - } - if (data.containsKey('created_at')) { - query.createdAt = data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] != null - ? data['created_at'] is String - ? DateTime.parse(data['created_at']) - : data['created_at'] - : new DateTime.now(); - } - if (data.containsKey('updated_at')) { - query.updatedAt = data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] != null - ? data['updated_at'] is String - ? DateTime.parse(data['updated_at']) - : data['updated_at'] - : new DateTime.now(); - } - } - return await UserQuery.updateUser(connection, query); - } -}