norm/model

Types

Model = ref object of RootObj
  id* {...}{.pk, ro.}: int64

Base type for models.

id corresponds to row id in DB. Updated automatically, do not update manually!

Funcs

func isModel[T: Model](val: T): bool
func isModel[T: Model](val: Option[T]): bool
func isModel[T](val: T): bool
func model[T: Model](val: T): Option[T]
func model[T: Model](val: Option[T]): Option[T]
func model[T](val: T): Option[Model]
This is never called and exists only to please the compiler.
func table(T: typedesc[Model]): string
Get table name for Model, which is the type name in single quotes.
func col(T: typedesc[Model]; fld: string): string
Get column name for a Model field, which is just the field name.
func col[T: Model](obj: T; fld: string): string
func fCol[T: Model](obj: T; fld: string): string
Get fully qualified column name with the table name: table.col.
func fCol[T: Model](obj: T; fld, tAls: string): string
Get fully qualified column name with the alias for the table name: alias.col.
func cols[T: Model](obj: T; force = false): seq[string]

Get columns for Model instance.

If force is true, fields with ro are included.

func rfCols[T: Model](obj: T; flds: seq[string] = @[]): seq[string]
Recursively get fully qualified column names for Model instance and its Model fields.
func joinGroups[T: Model](obj: T; flds: seq[string] = @[]): seq[
    tuple[tbl, tAls, lFld, rFld: string]]
For each Model field of Model instance, get:
  • table name for the field type
  • full column name for the field
  • full column name for id field of the field type

Used to construct JOIN statements: JOIN {tbl} AS {tAls} ON {lFld} = {rFld}