cast datetime, bump to +6

This commit is contained in:
Tobe O 2017-12-08 12:48:19 -05:00
parent ba0fb80448
commit 23f776c2f9
14 changed files with 37 additions and 27 deletions

View file

@ -1,3 +1,6 @@
# 1.0.0-alpha+6
* `DateTime` is now `CAST` on insertion and update operations.
# 1.0.0-alpha+3
Implemented `@hasOne`, with tests. Still missing `@hasMany`.
`belongsToMany` will likely be scrapped.

View file

@ -546,6 +546,14 @@ class PostgresOrmGenerator extends GeneratorForAnnotation<ORM> {
namedArguments: {'substitutionValues': map(substitutionValues)});
}
void printField(
PostgresBuildContext ctx, FieldElement field, StringBuffer buf) {
if (dateTimeTypeChecker.isAssignableFromType(field.type))
buf.write('CAST (@${field.name} AS ${ctx.columnInfo[field.name].type.name})');
else
buf.write('@${field.name}');
}
MethodBuilder buildUpdateMethod(PostgresBuildContext ctx) {
var meth = new MethodBuilder('update',
returnType:
@ -572,7 +580,7 @@ class PostgresOrmGenerator extends GeneratorForAnnotation<ORM> {
return;
else {
if (i++ > 0) buf.write(', ');
buf.write('@${field.name}');
printField(ctx, field, buf);
}
});
buf.write(') ');
@ -678,7 +686,7 @@ class PostgresOrmGenerator extends GeneratorForAnnotation<ORM> {
return;
else {
if (i++ > 0) buf.write(', ');
buf.write('@${field.name}');
printField(ctx, field, buf);
}
});

View file

@ -1,5 +1,5 @@
name: angel_orm_generator
version: 1.0.0-alpha+5
version: 1.0.0-alpha+6
description: Code generators for Angel's ORM.
author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/orm

View file

@ -122,7 +122,7 @@ class AuthorQuery {
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, @createdAt, @updatedAt) ');
'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);
@ -176,7 +176,7 @@ class AuthorQuery {
DateTime updatedAt}) async {
var __ormNow__ = new DateTime.now();
var result = await connection.query(
'INSERT INTO "authors" ("name", "created_at", "updated_at") VALUES (@name, @createdAt, @updatedAt) RETURNING "id", "name", "created_at", "updated_at";',
'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__,

View file

@ -130,7 +130,7 @@ class BookQuery {
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, @createdAt, @updatedAt, @authorId) ');
'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);
@ -189,7 +189,7 @@ class BookQuery {
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, @createdAt, @updatedAt, @authorId) RETURNING "id", "name", "created_at", "updated_at", "author_id";',
'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__,

View file

@ -130,7 +130,7 @@ class CarQuery {
DateTime createdAt,
DateTime updatedAt}) {
var buf = new StringBuffer(
'UPDATE "cars" SET ("make", "description", "family_friendly", "recalled_at", "created_at", "updated_at") = (@make, @description, @familyFriendly, @recalledAt, @createdAt, @updatedAt) ');
'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);
@ -191,7 +191,7 @@ class CarQuery {
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, @recalledAt, @createdAt, @updatedAt) RETURNING "id", "make", "description", "family_friendly", "recalled_at", "created_at", "updated_at";',
'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,

View file

@ -118,7 +118,7 @@ class CustomerQuery {
Stream<Customer> update(PostgreSQLConnection connection,
{DateTime createdAt, DateTime updatedAt}) {
var buf = new StringBuffer(
'UPDATE "customers" SET ("created_at", "updated_at") = (@createdAt, @updatedAt) ');
'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);
@ -169,7 +169,7 @@ class CustomerQuery {
{DateTime createdAt, DateTime updatedAt}) async {
var __ormNow__ = new DateTime.now();
var result = await connection.query(
'INSERT INTO "customers" ("created_at", "updated_at") VALUES (@createdAt, @updatedAt) RETURNING "id", "created_at", "updated_at";',
'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__

View file

@ -123,7 +123,7 @@ class FootQuery {
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, @createdAt, @updatedAt) ');
'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);
@ -177,7 +177,7 @@ class FootQuery {
{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, @createdAt, @updatedAt) RETURNING "id", "leg_id", "n_toes", "created_at", "updated_at";',
'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,

View file

@ -123,7 +123,7 @@ class FruitQuery {
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, @createdAt, @updatedAt) ');
'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);
@ -180,7 +180,7 @@ class FruitQuery {
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, @createdAt, @updatedAt) RETURNING "id", "tree_id", "common_name", "created_at", "updated_at";',
'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,

View file

@ -133,7 +133,7 @@ class LegQuery {
Stream<Leg> update(PostgreSQLConnection connection,
{String name, DateTime createdAt, DateTime updatedAt}) {
var buf = new StringBuffer(
'UPDATE "legs" SET ("name", "created_at", "updated_at") = (@name, @createdAt, @updatedAt) ');
'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);
@ -193,7 +193,7 @@ class LegQuery {
{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, @createdAt, @updatedAt) RETURNING "id", "name", "created_at", "updated_at";',
'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__,

View file

@ -130,7 +130,7 @@ class OrderQuery {
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, @orderDate, @shipperId, @createdAt, @updatedAt) ');
'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);
@ -191,7 +191,7 @@ class OrderQuery {
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, @orderDate, @shipperId, @createdAt, @updatedAt) RETURNING "id", "customer_id", "employee_id", "order_date", "shipper_id", "created_at", "updated_at";',
'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,
@ -233,8 +233,7 @@ class OrderQuery {
static Stream<Order> getAll(PostgreSQLConnection connection) =>
new OrderQuery().get(connection);
static joinCustomers(PostgreSQLConnection connection) {
}
static joinCustomers(PostgreSQLConnection connection) {}
}
class OrderQueryWhere {

View file

@ -122,7 +122,7 @@ class RoleQuery {
Stream<Role> update(PostgreSQLConnection connection,
{String name, DateTime createdAt, DateTime updatedAt}) {
var buf = new StringBuffer(
'UPDATE "roles" SET ("name", "created_at", "updated_at") = (@name, @createdAt, @updatedAt) ');
'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);
@ -174,7 +174,7 @@ class RoleQuery {
{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, @createdAt, @updatedAt) RETURNING "id", "name", "created_at", "updated_at";',
'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__,

View file

@ -131,7 +131,7 @@ class TreeQuery {
Stream<Tree> update(PostgreSQLConnection connection,
{int rings, DateTime createdAt, DateTime updatedAt}) {
var buf = new StringBuffer(
'UPDATE "trees" SET ("rings", "created_at", "updated_at") = (@rings, @createdAt, @updatedAt) ');
'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);
@ -192,7 +192,7 @@ class TreeQuery {
{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, @createdAt, @updatedAt) RETURNING "id", "rings", "created_at", "updated_at";',
'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__,

View file

@ -135,7 +135,7 @@ class UserQuery {
DateTime createdAt,
DateTime updatedAt}) {
var buf = new StringBuffer(
'UPDATE "users" SET ("username", "password", "email", "created_at", "updated_at") = (@username, @password, @email, @createdAt, @updatedAt) ');
'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);
@ -200,7 +200,7 @@ class UserQuery {
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, @createdAt, @updatedAt) RETURNING "id", "username", "password", "email", "created_at", "updated_at";',
'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,