Utility methods used internally by Fiber ORM.
Types
MutateClauses = object columns*: seq[string] placeholders*: seq[string] values*: seq[string]
- Data structure to hold information about the clauses that should be added to a query. How these clauses are used will depend on the query. This common data structure provides the information needed to create WHERE clauses, UPDATE clauses, etc. Source Edit
Procs
proc createParseStmt(t, value: NimNode): NimNode {....raises: [], tags: [].}
- Utility method to create the Nim cod required to parse a value coming from the a database query. This is used by functions like rowToModel to parse the dataabase columns into the Nim object fields. Source Edit
proc dbFormat(dt: DateTime): string {....raises: [], tags: [].}
- Format a DateTime for inclusion in a SQL Query. Source Edit
proc dbFormat(s: string): string {....raises: [], tags: [].}
- Format a string for inclusion in a SQL Query. Source Edit
proc dbFormat[T](item: T): string
- For all other types, fall back on a defined $ function to create a string version of the value we can include in an SQL query> Source Edit
proc dbNameToIdent(name: string): string {....raises: [], tags: [].}
- Map a DB name to a Nim identifier name. See the rules for name mapping Source Edit
proc identNameToDb(name: string): string {....raises: [], tags: [].}
-
Map a Nim identifier name to a DB name. See the rules for name mapping
TODO link above
Source Edit proc parseDbArray(val: string): seq[string] {....raises: [ValueError], tags: [].}
- Parse a Postgres array column into a Nim seq[string] Source Edit
proc parsePGDatetime(val: string): DateTime {....raises: [KeyError, SyntaxError, StudyError, ValueError, RegexInternalError, InvalidUnicodeError], tags: [TimeEffect].}
- Parse a Postgres datetime value into a Nim DateTime object. Source Edit
proc pluralize(name: string): string {....raises: [], tags: [].}
- Return the plural form of the given name. Source Edit
proc tableName(modelType: type): string
- Get the table name for a given model class Source Edit
proc tableName[T](rec: T): string
- Get the table name for a given record. Source Edit
proc typeOfColumn(modelType: NimNode; colName: string): NimNode {. ...raises: [Exception], tags: [].}
- Given a model type and a column name, return the Nim type for that column. Source Edit
Macros
macro columnNamesForModel(modelType: typed): seq[string]
- Return the column names corresponding to the the fields of the given model class Source Edit
macro listFields(t: typed): untyped
- Source Edit
macro modelName(model: object): string
- For a given concrete record object, return the name of the model class Source Edit
macro modelName(modelType: type): string
- Get the name of a given model class Source Edit
macro populateMutateClauses(t: typed; newRecord: bool; mc: var MutateClauses): untyped
- Given a record type, create the datastructure used to generate SQL clauses for the fields of this record type. Source Edit
macro rowToModel(modelType: typed; row: seq[string]): untyped
- Return a new Nim model object of type modelType populated with the values returned in the given database row Source Edit
Templates
template walkFieldDefs(t: NimNode; body: untyped)
- Iterate over every field of the given Nim object, yielding and defining fieldIdent and fieldType, the name of the field as a Nim Ident node and the type of the field as a Nim Type node respectively. Source Edit