Delete all gen files

This commit is contained in:
Tobe O 2018-05-03 23:52:21 -04:00
parent 9dd1dccf41
commit 856dfb9a92
44 changed files with 0 additions and 5715 deletions

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<AuthorQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<AuthorQueryWhere> _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<Author> get(PostgreSQLConnection connection) {
StreamController<Author> ctrl = new StreamController<Author>();
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<Author> getOne(int id, PostgreSQLConnection connection) {
var query = new AuthorQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Author> 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<Author>();
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<Author> delete(PostgreSQLConnection connection) {
StreamController<Author> ctrl = new StreamController<Author>();
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<Author> deleteOne(int id, PostgreSQLConnection connection) {
var query = new AuthorQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Author> 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<Author> insertAuthor(
PostgreSQLConnection connection, Author author) {
return AuthorQuery.insert(connection,
name: author.name,
createdAt: author.createdAt,
updatedAt: author.updatedAt);
}
static Future<Author> 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<Author> getAll(PostgreSQLConnection connection) =>
new AuthorQuery().get(connection);
}
class AuthorQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
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<String> 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';
}

View file

@ -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<List<Author>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Author> create(data, [Map params]) {
return AuthorQuery.insertAuthor(connection, applyData(data));
}
Future<Author> 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<Author> 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<Author> update(id, data, [Map params]) {
return AuthorQuery.updateAuthor(connection, applyData(data));
}
Future<Author> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<BookQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<BookQueryWhere> _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<Book> get(PostgreSQLConnection connection) {
StreamController<Book> ctrl = new StreamController<Book>();
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<Book> getOne(int id, PostgreSQLConnection connection) {
var query = new BookQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Book> 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<Book>();
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<Book> delete(PostgreSQLConnection connection) {
StreamController<Book> ctrl = new StreamController<Book>();
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<Book> deleteOne(int id, PostgreSQLConnection connection) {
var query = new BookQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Book> 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<Book> insertBook(PostgreSQLConnection connection, Book book,
{int authorId}) {
return BookQuery.insert(connection,
name: book.name,
createdAt: book.createdAt,
updatedAt: book.updatedAt,
authorId: authorId);
}
static Future<Book> 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<Book> getAll(PostgreSQLConnection connection) =>
new BookQuery().get(connection);
}
class BookQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
final StringSqlExpressionBuilder name = new StringSqlExpressionBuilder();
final DateTimeSqlExpressionBuilder createdAt =
new DateTimeSqlExpressionBuilder('books.created_at');
final DateTimeSqlExpressionBuilder updatedAt =
new DateTimeSqlExpressionBuilder('books.updated_at');
final NumericSqlExpressionBuilder<int> authorId =
new NumericSqlExpressionBuilder<int>();
String toWhereClause({bool keyword}) {
final List<String> 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';
}

View file

@ -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<List<Book>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Book> create(data, [Map params]) {
return BookQuery.insertBook(connection, applyData(data));
}
Future<Book> 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<Book> 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<Book> update(id, data, [Map params]) {
return BookQuery.updateBook(connection, applyData(data));
}
Future<Book> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<CarQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<CarQueryWhere> _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<Car> get(PostgreSQLConnection connection) {
StreamController<Car> ctrl = new StreamController<Car>();
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<Car> getOne(int id, PostgreSQLConnection connection) {
var query = new CarQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Car> 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<Car>();
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<Car> delete(PostgreSQLConnection connection) {
StreamController<Car> ctrl = new StreamController<Car>();
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<Car> deleteOne(int id, PostgreSQLConnection connection) {
var query = new CarQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Car> 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<Car> 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<Car> 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<Car> getAll(PostgreSQLConnection connection) =>
new CarQuery().get(connection);
}
class CarQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
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<String> 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';
}

View file

@ -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<List<Car>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Car> create(data, [Map params]) {
return CarQuery.insertCar(connection, applyData(data));
}
Future<Car> 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<Car> 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<Car> update(id, data, [Map params]) {
return CarQuery.updateCar(connection, applyData(data));
}
Future<Car> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<CustomerQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<CustomerQueryWhere> _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<Customer> get(PostgreSQLConnection connection) {
StreamController<Customer> ctrl = new StreamController<Customer>();
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<Customer> getOne(int id, PostgreSQLConnection connection) {
var query = new CustomerQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Customer> 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<Customer>();
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<Customer> delete(PostgreSQLConnection connection) {
StreamController<Customer> ctrl = new StreamController<Customer>();
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<Customer> deleteOne(int id, PostgreSQLConnection connection) {
var query = new CustomerQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Customer> 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<Customer> insertCustomer(
PostgreSQLConnection connection, Customer customer) {
return CustomerQuery.insert(connection,
createdAt: customer.createdAt, updatedAt: customer.updatedAt);
}
static Future<Customer> 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<Customer> getAll(PostgreSQLConnection connection) =>
new CustomerQuery().get(connection);
}
class CustomerQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
final DateTimeSqlExpressionBuilder createdAt =
new DateTimeSqlExpressionBuilder('customers.created_at');
final DateTimeSqlExpressionBuilder updatedAt =
new DateTimeSqlExpressionBuilder('customers.updated_at');
String toWhereClause({bool keyword}) {
final List<String> 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';
}

View file

@ -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<List<Customer>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Customer> create(data, [Map params]) {
return CustomerQuery.insertCustomer(connection, applyData(data));
}
Future<Customer> 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<Customer> 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<Customer> update(id, data, [Map params]) {
return CustomerQuery.updateCustomer(connection, applyData(data));
}
Future<Customer> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<FootQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<FootQueryWhere> _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<Foot> get(PostgreSQLConnection connection) {
StreamController<Foot> ctrl = new StreamController<Foot>();
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<Foot> getOne(int id, PostgreSQLConnection connection) {
var query = new FootQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Foot> 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<Foot>();
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<Foot> delete(PostgreSQLConnection connection) {
StreamController<Foot> ctrl = new StreamController<Foot>();
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<Foot> deleteOne(int id, PostgreSQLConnection connection) {
var query = new FootQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Foot> 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<Foot> insertFoot(PostgreSQLConnection connection, Foot foot) {
return FootQuery.insert(connection,
legId: foot.legId,
nToes: foot.nToes,
createdAt: foot.createdAt,
updatedAt: foot.updatedAt);
}
static Future<Foot> 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<Foot> getAll(PostgreSQLConnection connection) =>
new FootQuery().get(connection);
}
class FootQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
final NumericSqlExpressionBuilder<int> legId =
new NumericSqlExpressionBuilder<int>();
final NumericSqlExpressionBuilder<int> nToes =
new NumericSqlExpressionBuilder<int>();
final DateTimeSqlExpressionBuilder createdAt =
new DateTimeSqlExpressionBuilder('foots.created_at');
final DateTimeSqlExpressionBuilder updatedAt =
new DateTimeSqlExpressionBuilder('foots.updated_at');
String toWhereClause({bool keyword}) {
final List<String> 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';
}

View file

@ -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<List<Foot>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Foot> create(data, [Map params]) {
return FootQuery.insertFoot(connection, applyData(data));
}
Future<Foot> 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<Foot> 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<Foot> update(id, data, [Map params]) {
return FootQuery.updateFoot(connection, applyData(data));
}
Future<Foot> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<FruitQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<FruitQueryWhere> _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<Fruit> get(PostgreSQLConnection connection) {
StreamController<Fruit> ctrl = new StreamController<Fruit>();
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<Fruit> getOne(int id, PostgreSQLConnection connection) {
var query = new FruitQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Fruit> 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<Fruit>();
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<Fruit> delete(PostgreSQLConnection connection) {
StreamController<Fruit> ctrl = new StreamController<Fruit>();
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<Fruit> deleteOne(int id, PostgreSQLConnection connection) {
var query = new FruitQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Fruit> 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<Fruit> insertFruit(
PostgreSQLConnection connection, Fruit fruit) {
return FruitQuery.insert(connection,
treeId: fruit.treeId,
commonName: fruit.commonName,
createdAt: fruit.createdAt,
updatedAt: fruit.updatedAt);
}
static Future<Fruit> 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<Fruit> getAll(PostgreSQLConnection connection) =>
new FruitQuery().get(connection);
}
class FruitQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
final NumericSqlExpressionBuilder<int> treeId =
new NumericSqlExpressionBuilder<int>();
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<String> 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';
}

View file

@ -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<List<Fruit>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Fruit> create(data, [Map params]) {
return FruitQuery.insertFruit(connection, applyData(data));
}
Future<Fruit> 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<Fruit> 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<Fruit> update(id, data, [Map params]) {
return FruitQuery.updateFruit(connection, applyData(data));
}
Future<Fruit> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<LegQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<LegQueryWhere> _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<Leg> get(PostgreSQLConnection connection) {
StreamController<Leg> ctrl = new StreamController<Leg>();
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<Leg> getOne(int id, PostgreSQLConnection connection) {
var query = new LegQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Leg> 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<Leg>();
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<Leg> delete(PostgreSQLConnection connection) {
StreamController<Leg> ctrl = new StreamController<Leg>();
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<Leg> deleteOne(int id, PostgreSQLConnection connection) {
var query = new LegQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Leg> 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<Leg> insertLeg(PostgreSQLConnection connection, Leg leg) {
return LegQuery.insert(connection,
name: leg.name, createdAt: leg.createdAt, updatedAt: leg.updatedAt);
}
static Future<Leg> 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<Leg> getAll(PostgreSQLConnection connection) =>
new LegQuery().get(connection);
}
class LegQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
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<String> 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';
}

View file

@ -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<List<Leg>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Leg> create(data, [Map params]) {
return LegQuery.insertLeg(connection, applyData(data));
}
Future<Leg> 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<Leg> 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<Leg> update(id, data, [Map params]) {
return LegQuery.updateLeg(connection, applyData(data));
}
Future<Leg> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<OrderQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<OrderQueryWhere> _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<Order> get(PostgreSQLConnection connection) {
StreamController<Order> ctrl = new StreamController<Order>();
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<Order> getOne(int id, PostgreSQLConnection connection) {
var query = new OrderQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Order> 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<Order>();
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<Order> delete(PostgreSQLConnection connection) {
StreamController<Order> ctrl = new StreamController<Order>();
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<Order> deleteOne(int id, PostgreSQLConnection connection) {
var query = new OrderQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Order> 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<Order> 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<Order> 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<Order> getAll(PostgreSQLConnection connection) =>
new OrderQuery().get(connection);
static joinCustomers(PostgreSQLConnection connection) {}
}
class OrderQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
final NumericSqlExpressionBuilder<int> customerId =
new NumericSqlExpressionBuilder<int>();
final NumericSqlExpressionBuilder<int> employeeId =
new NumericSqlExpressionBuilder<int>();
final DateTimeSqlExpressionBuilder orderDate =
new DateTimeSqlExpressionBuilder('orders.order_date');
final NumericSqlExpressionBuilder<int> shipperId =
new NumericSqlExpressionBuilder<int>();
final DateTimeSqlExpressionBuilder createdAt =
new DateTimeSqlExpressionBuilder('orders.created_at');
final DateTimeSqlExpressionBuilder updatedAt =
new DateTimeSqlExpressionBuilder('orders.updated_at');
String toWhereClause({bool keyword}) {
final List<String> 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';
}

View file

@ -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<List<Order>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Order> create(data, [Map params]) {
return OrderQuery.insertOrder(connection, applyData(data));
}
Future<Order> 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<Order> 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<Order> update(id, data, [Map params]) {
return OrderQuery.updateOrder(connection, applyData(data));
}
Future<Order> 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);
}
}

View file

@ -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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<RoleQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<RoleQueryWhere> _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<Role> get(PostgreSQLConnection connection) {
StreamController<Role> ctrl = new StreamController<Role>();
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<Role> getOne(int id, PostgreSQLConnection connection) {
var query = new RoleQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Role> 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<Role>();
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<Role> delete(PostgreSQLConnection connection) {
StreamController<Role> ctrl = new StreamController<Role>();
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<Role> deleteOne(int id, PostgreSQLConnection connection) {
var query = new RoleQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Role> 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<Role> insertRole(PostgreSQLConnection connection, Role role) {
return RoleQuery.insert(connection,
name: role.name, createdAt: role.createdAt, updatedAt: role.updatedAt);
}
static Future<Role> 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<Role> getAll(PostgreSQLConnection connection) =>
new RoleQuery().get(connection);
}
class RoleQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
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<String> 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';
}

View file

@ -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<List<Role>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Role> create(data, [Map params]) {
return RoleQuery.insertRole(connection, applyData(data));
}
Future<Role> 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<Role> 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<Role> update(id, data, [Map params]) {
return RoleQuery.updateRole(connection, applyData(data));
}
Future<Role> 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);
}
}

View file

@ -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<Fruit> 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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<TreeQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<TreeQueryWhere> _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<Tree> get(PostgreSQLConnection connection) {
StreamController<Tree> ctrl = new StreamController<Tree>();
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<Tree> getOne(int id, PostgreSQLConnection connection) {
var query = new TreeQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<Tree> 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<Tree>();
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<Tree> delete(PostgreSQLConnection connection) {
StreamController<Tree> ctrl = new StreamController<Tree>();
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<Tree> deleteOne(int id, PostgreSQLConnection connection) {
var query = new TreeQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<Tree> 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<Tree> insertTree(PostgreSQLConnection connection, Tree tree) {
return TreeQuery.insert(connection,
rings: tree.rings,
createdAt: tree.createdAt,
updatedAt: tree.updatedAt);
}
static Future<Tree> 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<Tree> getAll(PostgreSQLConnection connection) =>
new TreeQuery().get(connection);
}
class TreeQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
final NumericSqlExpressionBuilder<int> rings =
new NumericSqlExpressionBuilder<int>();
final DateTimeSqlExpressionBuilder createdAt =
new DateTimeSqlExpressionBuilder('trees.created_at');
final DateTimeSqlExpressionBuilder updatedAt =
new DateTimeSqlExpressionBuilder('trees.updated_at');
String toWhereClause({bool keyword}) {
final List<String> 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';
}

View file

@ -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<List<Tree>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<Tree> create(data, [Map params]) {
return TreeQuery.insertTree(connection, applyData(data));
}
Future<Tree> 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<Tree> 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<Tree> update(id, data, [Map params]) {
return TreeQuery.updateTree(connection, applyData(data));
}
Future<Tree> 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);
}
}

View file

@ -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<Role> 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<String, dynamic> 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());
}
}

View file

@ -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');
}
}

View file

@ -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<UserQuery, bool> _unions = {};
String _sortKey;
String _sortMode;
int limit;
int offset;
final List<UserQueryWhere> _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<User> get(PostgreSQLConnection connection) {
StreamController<User> ctrl = new StreamController<User>();
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<User> getOne(int id, PostgreSQLConnection connection) {
var query = new UserQuery();
query.where.id.equals(id);
return query.get(connection).first.catchError((_) => null);
}
Stream<User> 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<User>();
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<User> delete(PostgreSQLConnection connection) {
StreamController<User> ctrl = new StreamController<User>();
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<User> deleteOne(int id, PostgreSQLConnection connection) {
var query = new UserQuery();
query.where.id.equals(id);
return query.delete(connection).first;
}
static Future<User> 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<User> 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<User> 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<User> getAll(PostgreSQLConnection connection) =>
new UserQuery().get(connection);
}
class UserQueryWhere {
final NumericSqlExpressionBuilder<int> id =
new NumericSqlExpressionBuilder<int>();
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<String> 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';
}

View file

@ -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<List<User>> index([Map params]) {
return buildQuery(params).get(connection).toList();
}
Future<User> create(data, [Map params]) {
return UserQuery.insertUser(connection, applyData(data));
}
Future<User> 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<User> 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<User> update(id, data, [Map params]) {
return UserQuery.updateUser(connection, applyData(data));
}
Future<User> 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);
}
}