From ff0c5e53054cb96d9b2f176c92558b51bdb0c730 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Fri, 2 Apr 2021 13:58:08 -0500 Subject: [PATCH] Update to support Nim 1.4.x+ --- fiber_orm.nimble | 4 ++-- src/fiber_orm.nim | 4 ++-- src/fiber_orm/util.nim | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fiber_orm.nimble b/fiber_orm.nimble index f824a43..3fadd3a 100644 --- a/fiber_orm.nimble +++ b/fiber_orm.nimble @@ -1,6 +1,6 @@ # Package -version = "0.3.0" +version = "0.3.1" author = "Jonathan Bernard" description = "Lightweight Postgres ORM for Nim." license = "GPL-3.0" @@ -10,4 +10,4 @@ srcDir = "src" # Dependencies -requires "nim >= 1.0.4" +requires "nim >= 1.4.0" diff --git a/src/fiber_orm.nim b/src/fiber_orm.nim index 1349dc1..b1790e3 100644 --- a/src/fiber_orm.nim +++ b/src/fiber_orm.nim @@ -25,12 +25,12 @@ proc createRecord*[T](db: DbConn, rec: T): T = " RETURNING *"), mc.values) result = rowToModel(T, newRow) - + proc updateRecord*[T](db: DbConn, rec: T): bool = var mc = newMutateClauses() populateMutateClauses(rec, false, mc) - let setClause = zip(mc.columns, mc.placeholders).mapIt(it.a & " = " & it.b).join(",") + let setClause = zip(mc.columns, mc.placeholders).mapIt(it[0] & " = " & it[1]).join(",") let numRowsUpdated = db.execAffectedRows(sql( "UPDATE " & tableName(rec) & " SET " & setClause & diff --git a/src/fiber_orm/util.nim b/src/fiber_orm/util.nim index b72ff8c..8213a7a 100644 --- a/src/fiber_orm/util.nim +++ b/src/fiber_orm/util.nim @@ -5,7 +5,9 @@ import nre except toSeq const UNDERSCORE_RUNE = "_".toRunes[0] const PG_TIMESTAMP_FORMATS = [ + "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:sszz", + "yyyy-MM-dd HH:mm:ss'.'fff", "yyyy-MM-dd HH:mm:ss'.'fffzz" ] @@ -278,7 +280,7 @@ proc typeOfColumn*(modelType: NimNode, colName: string): NimNode = proc isEmpty(val: int): bool = return val == 0 proc isEmpty(val: UUID): bool = return val.isZero -proc isEmpty(val: string): bool = return val.isNilOrWhitespace +proc isEmpty(val: string): bool = return val.isEmptyOrWhitespace macro populateMutateClauses*(t: typed, newRecord: bool, mc: var MutateClauses): untyped =