Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add dbIgnore pragma #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions sqlcipher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ proc hasRows*(rows: seq[ResultRow]): bool = rows.len > 0
template dbColumnName*(name: string) {.pragma.}
## Specifies the database column name for the object property

template dbIgnore*() {.pragma.}
## Specifies the object property should not be considered a DB column

template dbTableName*(name: string) {.pragma.}
## Specifies the database table name for the object

Expand All @@ -95,9 +98,9 @@ template tableName*(obj: auto | typedesc): string =


template enumInstanceDbColumns*(obj: auto,
fieldNameVar, fieldVar,
fieldNameVar, fieldVar, fieldIgnore,
body: untyped) =
## Expands a block over all serialized fields of an object.
## Expands a block over all fields of an object.
##
## Inside the block body, the passed `fieldNameVar` identifier
## will refer to the name of each field as a string. `fieldVar`
Expand All @@ -108,16 +111,22 @@ template enumInstanceDbColumns*(obj: auto,
type ObjType {.used.} = type(obj)

for fieldName, fieldVar in fieldPairs(obj):
when hasCustomPragmaFixed(ObjType, fieldName, dbColumnName):
when hasCustomPragmaFixed(ObjType, fieldName, dbIgnore):
const fieldIgnore = true
const fieldNameVar = fieldName
elif hasCustomPragmaFixed(ObjType, fieldName, dbColumnName):
const fieldIgnore = false
const fieldNameVar = getCustomPragmaFixed(ObjType, fieldName, dbColumnName)
else:
const fieldIgnore = false
const fieldNameVar = fieldName
body

proc unpack*(row: ResultRow, obj: var object) =
obj.enumInstanceDbColumns(dbColName, property):
type ColType = type property
property = row[dbColName, ColType]
obj.enumInstanceDbColumns(dbColName, property, ignore):
if not ignore:
type ColType = type property
property = row[dbColName, ColType]

#
# Custom.sqlcipher
Expand Down