Skip to content

Commit

Permalink
Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
moigagoo committed Dec 25, 2024
1 parent 73fd447 commit d0a6a2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion book/tutorial/rows.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ nbCode:
echo customer.user[]

nbText: """
You can pass a `Model` subtype to `select` proc instead of the object instance. Norm will instantiate the container object implicitly:
"""

nbCode:
let userFoo2 = dbConn.select(User, "email = ?", "[email protected]")
echo()

nbText: """
Note that this will only work with types that can be instantiated by calling `new <Type>`, i.e. types that don't require explicit instantiation.
If you query relationships that are nested, such as when customers can have pets and you want to query all pets of all customers of users with a specific email address, you will need to concatenate the foreign-key fields, separeted by a `_` in your query.
"""
Expand Down Expand Up @@ -245,4 +254,4 @@ If you need to check if a row selected by a given condition exists, use `exists`
nbCode:
echo dbConn.exists(Customer, "name = ?", "Alice")

nbSave
nbSave
4 changes: 4 additions & 0 deletions src/norm/postgres.nim
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ proc select*[T: Model](dbConn; typ: typedesc[T], cond: string, params: varargs[D
##[ Populate a sequence of `Model`_ instances from DB.
``typ`` is a `Model`_ subtype to contain the values.
**Note:** This works only with types that can be instantiated by calling ``new <Type>``, i.e. types that don't require explicit instantiation.
]##

result.add(new T)
Expand All @@ -313,6 +315,8 @@ proc selectAll*[T: Model](dbConn; typ: typedesc[T]): seq[T] =
``typ`` is a `Model`_ subtype to contain the values.
**Note:** This works only with types that can be instantiated by calling ``new <Type>``, i.e. types that don't require explicit instantiation.
**Warning:** this is a dangerous operation because you don't control how many rows will be fetched.
]##

Expand Down
4 changes: 4 additions & 0 deletions src/norm/sqlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ proc select*[T: Model](dbConn; typ: typedesc[T], cond: string, params: varargs[D
##[ Populate a sequence of `Model`_ instances from DB.
``typ`` is a `Model`_ subtype to contain the values.
**Note:** This works only with types that can be instantiated by calling ``new <Type>``, i.e. types that don't require explicit instantiation.
]##

result.add(new T)
Expand All @@ -284,6 +286,8 @@ proc selectAll*[T: Model](dbConn; typ: typedesc[T]): seq[T] =
``typ`` is a `Model`_ subtype to contain the values.
**Note:** This works only with types that can be instantiated by calling ``new <Type>``, i.e. types that don't require explicit instantiation.
**Warning:** this is a dangerous operation because you don't control how many rows will be fetched.
]##

Expand Down

0 comments on commit d0a6a2a

Please sign in to comment.