36 lines
809 B
Nim

import db_postgres, fiber_orm, sequtils, uuids
import ./models
export fiber_orm.NotFoundError
type
PMApiDb* = ref object
conn: DbConn
proc connect*(connString: string): PMApiDb =
result = PMApiDb(conn: open("", "", "", connString))
generateProcsForModels(PMApiDb, [
User,
ApiToken,
Measure,
Measurement,
ClientLogEntry
])
generateLookup(PMApiDb, User, @["email"])
generateLookup(PMApiDb, ApiToken, @["userId"])
generateLookup(PMApiDb, ApiToken, @["hashedToken"])
generateLookup(PMApiDb, Measure, @["userId"])
generateLookup(PMApiDb, Measure, @["userId", "id"])
generateLookup(PMApiDb, Measure, @["userId", "slug"])
generateLookup(PMApiDb, Measurement, @["measureId"])
generateLookup(PMApiDb, Measurement, @["measureId", "id"])
generateLookup(PMApiDb, ClientLogEntry, @["userId"])