Add generated documentations (for use with GitHub pages).

This commit is contained in:
2022-09-03 21:01:24 -05:00
parent a3dbb0bbbc
commit 7d45346bb6
15 changed files with 5909 additions and 23 deletions

303
docs/fiber_orm/pool.html Normal file
View File

@ -0,0 +1,303 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- CSS -->
<title>src/fiber_orm/pool</title>
<link rel="stylesheet" type="text/css" href="../nimdoc.out.css">
<script type="text/javascript" src="../dochack.js"></script>
<script type="text/javascript">
function main() {
var pragmaDots = document.getElementsByClassName("pragmadots");
for (var i = 0; i < pragmaDots.length; i++) {
pragmaDots[i].onclick = function(event) {
// Hide tease
event.target.parentNode.style.display = "none";
// Show actual
event.target.parentNode.nextElementSibling.style.display = "inline";
}
}
function switchTheme(e) {
if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
} else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
}
}
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
if (toggleSwitch !== null) {
toggleSwitch.addEventListener('change', switchTheme, false);
}
var currentTheme = localStorage.getItem('theme');
if (!currentTheme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
currentTheme = 'dark';
}
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark' && toggleSwitch !== null) {
toggleSwitch.checked = true;
}
}
}
window.addEventListener('DOMContentLoaded', main);
</script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">src/fiber_orm/pool</h1>
<div class="row">
<div class="three columns">
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round"></div>
</label>
&nbsp;&nbsp;&nbsp; <em>Dark Mode</em>
</div>
<div id="global-links">
<ul class="simple">
<li>
<a href="../theindex.html">Index</a>
</li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="text" id="searchInput"
onkeyup="search()" />
</div>
<div>
Group by:
<select onchange="groupBy(this.value)">
<option value="section">Section</option>
<option value="type">Type</option>
</select>
</div>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#DbConnPool"
title="DbConnPool = ref object
conns: seq[PooledDbConn]
cfg: DbConnPoolConfig
lastId: int">DbConnPool</a></li>
<li><a class="reference" href="#DbConnPoolConfig"
title="DbConnPoolConfig = object
connect*: () -&gt; DbConn ## Factory procedure to create a new DBConn
poolSize*: int ## The pool capacity.
hardCap*: bool ## Is the pool capacity a hard cap?
##
## When `false`, the pool can grow beyond the configured
## capacity, but will release connections down to the its
## capacity (no less than `poolSize`).
##
## When `true` the pool will not create more than its
## configured capacity. It a connection is requested, none
## are free, and the pool is at capacity, this will result
## in an Error being raised.
healthCheckQuery*: string ## Should be a simple and fast SQL query that the
## pool can use to test the liveliness of pooled
## connections.">DbConnPoolConfig</a></li>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#12" id="62">Procs</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">initDbConnPool
<li><a class="reference" href="#initDbConnPool%2CDbConnPoolConfig"
title="initDbConnPool(cfg: DbConnPoolConfig): DbConnPool">initDbConnPool(cfg: DbConnPoolConfig): DbConnPool</a></li>
</ul>
<ul class="simple nested-toc-section">release
<li><a class="reference" href="#release%2CDbConnPool%2Cint"
title="release(pool: DbConnPool; connId: int): void">release(pool: DbConnPool; connId: int): void</a></li>
</ul>
<ul class="simple nested-toc-section">take
<li><a class="reference" href="#take%2CDbConnPool"
title="take(pool: DbConnPool): tuple[id: int, conn: DbConn]">take(pool: DbConnPool): tuple[id: int, conn: DbConn]</a></li>
</ul>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#18" id="68">Templates</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">withConn
<li><a class="reference" href="#withConn.t%2CDbConnPool%2Cuntyped"
title="withConn(pool: DbConnPool; stmt: untyped): untyped">withConn(pool: DbConnPool; stmt: untyped): untyped</a></li>
</ul>
</ul>
</li>
</ul>
</div>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L1"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
<div class="nine columns" id="content">
<div id="tocRoot"></div>
<p class="module-desc">Simple database connection pooling implementation compatible with Fiber ORM.</p>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="DbConnPool">
<dt><pre><a href="pool.html#DbConnPool"><span class="Identifier">DbConnPool</span></a> <span class="Other">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
<span class="Identifier">conns</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">PooledDbConn</span><span class="Other">]</span>
<span class="Identifier">cfg</span><span class="Other">:</span> <a href="pool.html#DbConnPoolConfig"><span class="Identifier">DbConnPoolConfig</span></a>
<span class="Identifier">lastId</span><span class="Other">:</span> <span class="Identifier">int</span>
</pre></dt>
<dd>
Database connection pool
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L35"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L35" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="DbConnPoolConfig">
<dt><pre><a href="pool.html#DbConnPoolConfig"><span class="Identifier">DbConnPoolConfig</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">connect</span><span class="Operator">*</span><span class="Other">:</span> <span class="Other">(</span><span class="Other">)</span> <span class="Operator">-&gt;</span> <span class="Identifier">DbConn</span> <span class="Comment">## Factory procedure to create a new DBConn</span>
<span class="Identifier">poolSize</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span> <span class="Comment">## The pool capacity.</span>
<span class="Identifier">hardCap</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span> <span class="Comment">## Is the pool capacity a hard cap?</span>
<span class="Comment">## </span>
<span class="Comment">## When `false`, the pool can grow beyond the configured</span>
<span class="Comment">## capacity, but will release connections down to the its</span>
<span class="Comment">## capacity (no less than `poolSize`).</span>
<span class="Comment">## </span>
<span class="Comment">## When `true` the pool will not create more than its</span>
<span class="Comment">## configured capacity. It a connection is requested, none</span>
<span class="Comment">## are free, and the pool is at capacity, this will result</span>
<span class="Comment">## in an Error being raised.</span>
<span class="Identifier">healthCheckQuery</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## Should be a simple and fast SQL query that the</span>
<span class="Comment">## pool can use to test the liveliness of pooled</span>
<span class="Comment">## connections.</span>
</pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L13"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L13" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="initDbConnPool,DbConnPoolConfig">
<dt><pre><span class="Keyword">proc</span> <a href="#initDbConnPool%2CDbConnPoolConfig"><span class="Identifier">initDbConnPool</span></a><span class="Other">(</span><span class="Identifier">cfg</span><span class="Other">:</span> <a href="pool.html#DbConnPoolConfig"><span class="Identifier">DbConnPoolConfig</span></a><span class="Other">)</span><span class="Other">:</span> <a href="pool.html#DbConnPool"><span class="Identifier">DbConnPool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L47"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L47" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="release,DbConnPool,int">
<dt><pre><span class="Keyword">proc</span> <a href="#release%2CDbConnPool%2Cint"><span class="Identifier">release</span></a><span class="Other">(</span><span class="Identifier">pool</span><span class="Other">:</span> <a href="pool.html#DbConnPool"><span class="Identifier">DbConnPool</span></a><span class="Other">;</span> <span class="Identifier">connId</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">void</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Release a connection back to the pool.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L116"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L116" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="take,DbConnPool">
<dt><pre><span class="Keyword">proc</span> <a href="#take%2CDbConnPool"><span class="Identifier">take</span></a><span class="Other">(</span><span class="Identifier">pool</span><span class="Other">:</span> <a href="pool.html#DbConnPool"><span class="Identifier">DbConnPool</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">[</span><span class="Identifier">id</span><span class="Other">:</span> <span class="Identifier">int</span><span class="Other">,</span> <span class="Identifier">conn</span><span class="Other">:</span> <span class="Identifier">DbConn</span><span class="Other">]</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">RootEffect</span><span class="Other">,</span> <span class="Identifier">ReadDbEffect</span><span class="Other">,</span> <span class="Identifier">DbEffect</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Request a connection from the pool. Returns a DbConn if the pool has free connections, or if it has the capacity to create a new connection. If the pool is configured with a hard capacity limit and is out of free connections, this will raise an Error.</p>
<p>Connections taken must be returned via <tt class="docutils literal"><span class="pre"><span class="Identifier">release</span></span></tt> when the caller is finished using them in order for them to be released back to the pool.</p>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L94"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L94" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="18">
<h1><a class="toc-backref" href="#18">Templates</a></h1>
<dl class="item">
<div id="withConn.t,DbConnPool,untyped">
<dt><pre><span class="Keyword">template</span> <a href="#withConn.t%2CDbConnPool%2Cuntyped"><span class="Identifier">withConn</span></a><span class="Other">(</span><span class="Identifier">pool</span><span class="Other">:</span> <a href="pool.html#DbConnPool"><span class="Identifier">DbConnPool</span></a><span class="Other">;</span> <span class="Identifier">stmt</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
<dd>
<p>Convenience template to provide a connection from the pool for use in a statement block, automatically releasing that connnection when done.</p>
<p>The provided connection is injected as the variable <tt class="docutils literal"><span class="pre"><span class="Identifier">conn</span></span></tt> in the statement body.</p>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/pool.nim#L122"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/pool.nim#L122" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
</div>
</div>
<div class="row">
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br/>
<small style="color: var(--hint);">Made with Nim. Generated: 2022-09-04 02:31:19 UTC</small>
</div>
</div>
</div>
</div>
</body>
</html>

6
docs/fiber_orm/pool.idx Normal file
View File

@ -0,0 +1,6 @@
DbConnPoolConfig fiber_orm/pool.html#DbConnPoolConfig pool: DbConnPoolConfig
DbConnPool fiber_orm/pool.html#DbConnPool pool: DbConnPool
initDbConnPool fiber_orm/pool.html#initDbConnPool,DbConnPoolConfig pool: initDbConnPool(cfg: DbConnPoolConfig): DbConnPool
take fiber_orm/pool.html#take,DbConnPool pool: take(pool: DbConnPool): tuple[id: int, conn: DbConn]
release fiber_orm/pool.html#release,DbConnPool,int pool: release(pool: DbConnPool; connId: int): void
withConn fiber_orm/pool.html#withConn.t,DbConnPool,untyped pool: withConn(pool: DbConnPool; stmt: untyped): untyped

524
docs/fiber_orm/util.html Normal file
View File

@ -0,0 +1,524 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- CSS -->
<title>src/fiber_orm/util</title>
<link rel="stylesheet" type="text/css" href="../nimdoc.out.css">
<script type="text/javascript" src="../dochack.js"></script>
<script type="text/javascript">
function main() {
var pragmaDots = document.getElementsByClassName("pragmadots");
for (var i = 0; i < pragmaDots.length; i++) {
pragmaDots[i].onclick = function(event) {
// Hide tease
event.target.parentNode.style.display = "none";
// Show actual
event.target.parentNode.nextElementSibling.style.display = "inline";
}
}
function switchTheme(e) {
if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
} else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
}
}
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
if (toggleSwitch !== null) {
toggleSwitch.addEventListener('change', switchTheme, false);
}
var currentTheme = localStorage.getItem('theme');
if (!currentTheme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
currentTheme = 'dark';
}
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark' && toggleSwitch !== null) {
toggleSwitch.checked = true;
}
}
}
window.addEventListener('DOMContentLoaded', main);
</script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">src/fiber_orm/util</h1>
<div class="row">
<div class="three columns">
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round"></div>
</label>
&nbsp;&nbsp;&nbsp; <em>Dark Mode</em>
</div>
<div id="global-links">
<ul class="simple">
<li>
<a href="../theindex.html">Index</a>
</li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="text" id="searchInput"
onkeyup="search()" />
</div>
<div>
Group by:
<select onchange="groupBy(this.value)">
<option value="section">Section</option>
<option value="type">Type</option>
</select>
</div>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#MutateClauses"
title="MutateClauses = object
columns*: seq[string]
placeholders*: seq[string]
values*: seq[string]">MutateClauses</a></li>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#12" id="62">Procs</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">createParseStmt
<li><a class="reference" href="#createParseStmt%2CNimNode%2CNimNode"
title="createParseStmt(t, value: NimNode): NimNode">createParseStmt(t, value: NimNode): NimNode</a></li>
</ul>
<ul class="simple nested-toc-section">dbFormat
<li><a class="reference" href="#dbFormat%2CDateTime"
title="dbFormat(dt: DateTime): string">dbFormat(dt: DateTime): string</a></li>
<li><a class="reference" href="#dbFormat%2Cstring"
title="dbFormat(s: string): string">dbFormat(s: string): string</a></li>
<li><a class="reference" href="#dbFormat%2CT"
title="dbFormat[T](item: T): string">dbFormat[T](item: T): string</a></li>
<li><a class="reference" href="#dbFormat%2Cseq%5BT%5D"
title="dbFormat[T](list: seq[T]): string">dbFormat[T](list: seq[T]): string</a></li>
</ul>
<ul class="simple nested-toc-section">dbNameToIdent
<li><a class="reference" href="#dbNameToIdent%2Cstring"
title="dbNameToIdent(name: string): string">dbNameToIdent(name: string): string</a></li>
</ul>
<ul class="simple nested-toc-section">identNameToDb
<li><a class="reference" href="#identNameToDb%2Cstring"
title="identNameToDb(name: string): string">identNameToDb(name: string): string</a></li>
</ul>
<ul class="simple nested-toc-section">parseDbArray
<li><a class="reference" href="#parseDbArray%2Cstring"
title="parseDbArray(val: string): seq[string]">parseDbArray(val: string): seq[string]</a></li>
</ul>
<ul class="simple nested-toc-section">parsePGDatetime
<li><a class="reference" href="#parsePGDatetime%2Cstring"
title="parsePGDatetime(val: string): DateTime">parsePGDatetime(val: string): DateTime</a></li>
</ul>
<ul class="simple nested-toc-section">pluralize
<li><a class="reference" href="#pluralize%2Cstring"
title="pluralize(name: string): string">pluralize(name: string): string</a></li>
</ul>
<ul class="simple nested-toc-section">tableName
<li><a class="reference" href="#tableName%2Ctype"
title="tableName(modelType: type): string">tableName(modelType: type): string</a></li>
<li><a class="reference" href="#tableName%2CT"
title="tableName[T](rec: T): string">tableName[T](rec: T): string</a></li>
</ul>
<ul class="simple nested-toc-section">typeOfColumn
<li><a class="reference" href="#typeOfColumn%2CNimNode%2Cstring"
title="typeOfColumn(modelType: NimNode; colName: string): NimNode">typeOfColumn(modelType: NimNode; colName: string): NimNode</a></li>
</ul>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#17" id="67">Macros</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">columnNamesForModel
<li><a class="reference" href="#columnNamesForModel.m%2Ctyped"
title="columnNamesForModel(modelType: typed): seq[string]">columnNamesForModel(modelType: typed): seq[string]</a></li>
</ul>
<ul class="simple nested-toc-section">listFields
<li><a class="reference" href="#listFields.m%2Ctyped"
title="listFields(t: typed): untyped">listFields(t: typed): untyped</a></li>
</ul>
<ul class="simple nested-toc-section">modelName
<li><a class="reference" href="#modelName.m"
title="modelName(model: object): string">modelName(model: object): string</a></li>
<li><a class="reference" href="#modelName.m%2Ctype"
title="modelName(modelType: type): string">modelName(modelType: type): string</a></li>
</ul>
<ul class="simple nested-toc-section">populateMutateClauses
<li><a class="reference" href="#populateMutateClauses.m%2Ctyped%2Cbool%2CMutateClauses"
title="populateMutateClauses(t: typed; newRecord: bool; mc: var MutateClauses): untyped">populateMutateClauses(t: typed; newRecord: bool; mc: var MutateClauses): untyped</a></li>
</ul>
<ul class="simple nested-toc-section">rowToModel
<li><a class="reference" href="#rowToModel.m%2Ctyped%2Cseq%5Bstring%5D"
title="rowToModel(modelType: typed; row: seq[string]): untyped">rowToModel(modelType: typed; row: seq[string]): untyped</a></li>
</ul>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#18" id="68">Templates</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">walkFieldDefs
<li><a class="reference" href="#walkFieldDefs.t%2CNimNode%2Cuntyped"
title="walkFieldDefs(t: NimNode; body: untyped)">walkFieldDefs(t: NimNode; body: untyped)</a></li>
</ul>
</ul>
</li>
</ul>
</div>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L1"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
<div class="nine columns" id="content">
<div id="tocRoot"></div>
<p class="module-desc">Utility methods used internally by Fiber ORM.</p>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="MutateClauses">
<dt><pre><a href="util.html#MutateClauses"><span class="Identifier">MutateClauses</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">columns</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span>
<span class="Identifier">placeholders</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span>
<span class="Identifier">values</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span>
</pre></dt>
<dd>
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.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L12"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L12" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="createParseStmt,NimNode,NimNode">
<dt><pre><span class="Keyword">proc</span> <a href="#createParseStmt%2CNimNode%2CNimNode"><span class="Identifier">createParseStmt</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">,</span> <span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">NimNode</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">NimNode</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Utility method to create the Nim cod required to parse a value coming from the a database query. This is used by functions like <tt class="docutils literal"><span class="pre"><span class="Identifier">rowToModel</span></span></tt> to parse the dataabase columns into the Nim object fields.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L190"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L190" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="dbFormat,DateTime">
<dt><pre><span class="Keyword">proc</span> <a href="#dbFormat%2CDateTime"><span class="Identifier">dbFormat</span></a><span class="Other">(</span><span class="Identifier">dt</span><span class="Other">:</span> <span class="Identifier">DateTime</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Format a DateTime for inclusion in a SQL Query.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L75"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L75" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="dbFormat,string">
<dt><pre><span class="Keyword">proc</span> <a href="#dbFormat%2Cstring"><span class="Identifier">dbFormat</span></a><span class="Other">(</span><span class="Identifier">s</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Format a string for inclusion in a SQL Query.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L71"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L71" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="dbFormat,T">
<dt><pre><span class="Keyword">proc</span> <a href="#dbFormat%2CT"><span class="Identifier">dbFormat</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">item</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>
For all other types, fall back on a defined <tt class="docutils literal"><span class="pre"><span class="Operator">$</span></span></tt> function to create a string version of the value we can include in an SQL query&gt;
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L83"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L83" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="dbFormat,seq[T]">
<dt><pre><span class="Keyword">proc</span> <a href="#dbFormat%2Cseq%5BT%5D"><span class="Identifier">dbFormat</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">list</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>
Format a <tt class="docutils literal"><span class="pre"><span class="Identifier">seq</span></span></tt> for inclusion in a SQL Query.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L79"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L79" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="dbNameToIdent,string">
<dt><pre><span class="Keyword">proc</span> <a href="#dbNameToIdent%2Cstring"><span class="Identifier">dbNameToIdent</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Map a DB name to a Nim identifier name. See the <a class="reference external" href="../fiber_orm.html">rules for name mapping</a>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L58"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L58" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="identNameToDb,string">
<dt><pre><span class="Keyword">proc</span> <a href="#identNameToDb%2Cstring"><span class="Identifier">identNameToDb</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Map a Nim identifier name to a DB name. See the <a class="reference external" href="../fiber_orm.html">rules for name mapping</a></p>
<p>TODO link above</p>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L37"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L37" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="parseDbArray,string">
<dt><pre><span class="Keyword">proc</span> <a href="#parseDbArray%2Cstring"><span class="Identifier">parseDbArray</span></a><span class="Other">(</span><span class="Identifier">val</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">ValueError</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Parse a Postgres array column into a Nim seq[string]
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L131"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L131" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="parsePGDatetime,string">
<dt><pre><span class="Keyword">proc</span> <a href="#parsePGDatetime%2Cstring"><span class="Identifier">parsePGDatetime</span></a><span class="Other">(</span><span class="Identifier">val</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">DateTime</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">KeyError</span><span class="Other">,</span> <span class="Identifier">SyntaxError</span><span class="Other">,</span>
<span class="Identifier">StudyError</span><span class="Other">,</span> <span class="Identifier">ValueError</span><span class="Other">,</span> <span class="Identifier">RegexInternalError</span><span class="Other">,</span> <span class="Identifier">InvalidUnicodeError</span><span class="Other">]</span><span class="Other">,</span>
<span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">TimeEffect</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Parse a Postgres datetime value into a Nim DateTime object.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L91"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L91" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="pluralize,string">
<dt><pre><span class="Keyword">proc</span> <a href="#pluralize%2Cstring"><span class="Identifier">pluralize</span></a><span class="Other">(</span><span class="Identifier">name</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Return the plural form of the given name.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L23"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L23" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="tableName,type">
<dt><pre><span class="Keyword">proc</span> <a href="#tableName%2Ctype"><span class="Identifier">tableName</span></a><span class="Other">(</span><span class="Identifier">modelType</span><span class="Other">:</span> <span class="Identifier">type</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>
Get the <a class="reference external" href="../fiber_orm.html">table name</a> for a given <a class="reference external" href="../fiber_orm.html#objectminusrelational-modeling-model-class">model class</a>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L63"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L63" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="tableName,T">
<dt><pre><span class="Keyword">proc</span> <a href="#tableName%2CT"><span class="Identifier">tableName</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">rec</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>
Get the <a class="reference external" href="../fiber_orm.html">table name</a> for a given record.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L67"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L67" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="typeOfColumn,NimNode,string">
<dt><pre><span class="Keyword">proc</span> <a href="#typeOfColumn%2CNimNode%2Cstring"><span class="Identifier">typeOfColumn</span></a><span class="Other">(</span><span class="Identifier">modelType</span><span class="Other">:</span> <span class="Identifier">NimNode</span><span class="Other">;</span> <span class="Identifier">colName</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">NimNode</span> {.
<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Identifier">Exception</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Given a model type and a column name, return the Nim type for that column.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L308"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L308" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="17">
<h1><a class="toc-backref" href="#17">Macros</a></h1>
<dl class="item">
<div id="columnNamesForModel.m,typed">
<dt><pre><span class="Keyword">macro</span> <a href="#columnNamesForModel.m%2Ctyped"><span class="Identifier">columnNamesForModel</span></a><span class="Other">(</span><span class="Identifier">modelType</span><span class="Other">:</span> <span class="Identifier">typed</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span></pre></dt>
<dd>
Return the column names corresponding to the the fields of the given <a class="reference external" href="../fiber_orm.html#objectminusrelational-modeling-model-class">model class</a>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L274"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L274" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="listFields.m,typed">
<dt><pre><span class="Keyword">macro</span> <a href="#listFields.m%2Ctyped"><span class="Identifier">listFields</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Identifier">typed</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L300"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L300" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="modelName.m">
<dt><pre><span class="Keyword">macro</span> <a href="#modelName.m"><span class="Identifier">modelName</span></a><span class="Other">(</span><span class="Identifier">model</span><span class="Other">:</span> <span class="Keyword">object</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>
For a given concrete record object, return the name of the <a class="reference external" href="../fiber_orm.html#objectminusrelational-modeling-model-class">model class</a>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L29"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L29" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="modelName.m,type">
<dt><pre><span class="Keyword">macro</span> <a href="#modelName.m%2Ctype"><span class="Identifier">modelName</span></a><span class="Other">(</span><span class="Identifier">modelType</span><span class="Other">:</span> <span class="Identifier">type</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">string</span></pre></dt>
<dd>
Get the name of a given <a class="reference external" href="../fiber_orm.html#objectminusrelational-modeling-model-class">model class</a>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L33"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L33" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="populateMutateClauses.m,typed,bool,MutateClauses">
<dt><pre><span class="Keyword">macro</span> <a href="#populateMutateClauses.m%2Ctyped%2Cbool%2CMutateClauses"><span class="Identifier">populateMutateClauses</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Identifier">typed</span><span class="Other">;</span> <span class="Identifier">newRecord</span><span class="Other">:</span> <span class="Identifier">bool</span><span class="Other">;</span> <span class="Identifier">mc</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="util.html#MutateClauses"><span class="Identifier">MutateClauses</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
<dd>
Given a record type, create the datastructure used to generate SQL clauses for the fields of this record type.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L330"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L330" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="rowToModel.m,typed,seq[string]">
<dt><pre><span class="Keyword">macro</span> <a href="#rowToModel.m%2Ctyped%2Cseq%5Bstring%5D"><span class="Identifier">rowToModel</span></a><span class="Other">(</span><span class="Identifier">modelType</span><span class="Other">:</span> <span class="Identifier">typed</span><span class="Other">;</span> <span class="Identifier">row</span><span class="Other">:</span> <span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">string</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">untyped</span></pre></dt>
<dd>
Return a new Nim model object of type <tt class="docutils literal"><span class="pre"><span class="Identifier">modelType</span></span></tt> populated with the values returned in the given database <tt class="docutils literal"><span class="pre"><span class="Identifier">row</span></span></tt>
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L284"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L284" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="18">
<h1><a class="toc-backref" href="#18">Templates</a></h1>
<dl class="item">
<div id="walkFieldDefs.t,NimNode,untyped">
<dt><pre><span class="Keyword">template</span> <a href="#walkFieldDefs.t%2CNimNode%2Cuntyped"><span class="Identifier">walkFieldDefs</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Identifier">NimNode</span><span class="Other">;</span> <span class="Identifier">body</span><span class="Other">:</span> <span class="Identifier">untyped</span><span class="Other">)</span></pre></dt>
<dd>
Iterate over every field of the given Nim object, yielding and defining <tt class="docutils literal"><span class="pre"><span class="Identifier">fieldIdent</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">fieldType</span></span></tt>, the name of the field as a Nim Ident node and the type of the field as a Nim Type node respectively.
&nbsp;&nbsp;<a
href="https://github.com/jdbernard/fiber-orm/tree/version-1-6/src/fiber_orm/util.nim#L251"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/jdbernard/fiber-orm/edit/devel/src/fiber_orm/util.nim#L251" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
</div>
</div>
<div class="row">
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br/>
<small style="color: var(--hint);">Made with Nim. Generated: 2022-09-04 02:31:20 UTC</small>
</div>
</div>
</div>
</div>
</body>
</html>

21
docs/fiber_orm/util.idx Normal file
View File

@ -0,0 +1,21 @@
MutateClauses fiber_orm/util.html#MutateClauses util: MutateClauses
pluralize fiber_orm/util.html#pluralize,string util: pluralize(name: string): string
modelName fiber_orm/util.html#modelName.m util: modelName(model: object): string
modelName fiber_orm/util.html#modelName.m,type util: modelName(modelType: type): string
identNameToDb fiber_orm/util.html#identNameToDb,string util: identNameToDb(name: string): string
dbNameToIdent fiber_orm/util.html#dbNameToIdent,string util: dbNameToIdent(name: string): string
tableName fiber_orm/util.html#tableName,type util: tableName(modelType: type): string
tableName fiber_orm/util.html#tableName,T util: tableName[T](rec: T): string
dbFormat fiber_orm/util.html#dbFormat,string util: dbFormat(s: string): string
dbFormat fiber_orm/util.html#dbFormat,DateTime util: dbFormat(dt: DateTime): string
dbFormat fiber_orm/util.html#dbFormat,seq[T] util: dbFormat[T](list: seq[T]): string
dbFormat fiber_orm/util.html#dbFormat,T util: dbFormat[T](item: T): string
parsePGDatetime fiber_orm/util.html#parsePGDatetime,string util: parsePGDatetime(val: string): DateTime
parseDbArray fiber_orm/util.html#parseDbArray,string util: parseDbArray(val: string): seq[string]
createParseStmt fiber_orm/util.html#createParseStmt,NimNode,NimNode util: createParseStmt(t, value: NimNode): NimNode
walkFieldDefs fiber_orm/util.html#walkFieldDefs.t,NimNode,untyped util: walkFieldDefs(t: NimNode; body: untyped)
columnNamesForModel fiber_orm/util.html#columnNamesForModel.m,typed util: columnNamesForModel(modelType: typed): seq[string]
rowToModel fiber_orm/util.html#rowToModel.m,typed,seq[string] util: rowToModel(modelType: typed; row: seq[string]): untyped
listFields fiber_orm/util.html#listFields.m,typed util: listFields(t: typed): untyped
typeOfColumn fiber_orm/util.html#typeOfColumn,NimNode,string util: typeOfColumn(modelType: NimNode; colName: string): NimNode
populateMutateClauses fiber_orm/util.html#populateMutateClauses.m,typed,bool,MutateClauses util: populateMutateClauses(t: typed; newRecord: bool; mc: var MutateClauses): untyped