<p>
</p>
+ <h3>Usage:</h3>
+ <ul>
+ <pre class="example">
+ -- File: samples/sample1.lua
+
+ local ejdb = require("ejdb")
+ local inspect = require("ejdb.inspect")
+ local Q = ejdb.Q
+
+ -- Used modes:
+ -- 'r' - read
+ -- 'w' - write
+ -- 'c' - create db if not exists
+ -- 't' - truncate existing db
+ local db = ejdb.open("zoo", "rwct")
+
+ -- Unordered lua table
+ local parrot1 = {
+ name = "Grenny",
+ type = "African Grey",
+ male = true,
+ age = 1,
+ birthhdate = ejdb.toDateNow(),
+ likes = { "green color", "night", "toys" },
+ extra1 = ejdb.toNull()
+ }
+
+ -- Preserve order of BSON keys
+ local parrot2 = Q();
+ parrot2:KV("name", "Bounty"):KV("type", "Cockatoo"):KV("male", false)
+ parrot2:KV("age", 15):KV("birthdate",
+ ejdb.toDate({ year = 2013, month = 1, day = 1,
+ hour = 0, sec = 1 }))
+ parrot2:KV("likes", { "sugar cane" }):KV("extra1", ejdb.toNull())
+
+ --IF YOU WANT SOME DATA INSPECTIONS:
+ --print(ejdb.print_bson(parrot2:toBSON()))
+ --local obj = ejdb.from_bson(parrot2:toBSON())
+ --print(inspect(obj));
+
+ db:save("parrots2", parrot1)
+ db:save("parrots2", parrot2)
+
+ -- Below two equivalent queries:
+ -- Q1
+ local res, count, log =
+ db:find("parrots2", Q("likes", "toys"):OrderBy("name asc", "age desc"))
+ for i = 1, #res do -- iterate one
+ local ob = res:object(i)
+ print("" .. ob["name"] .. " likes toys #1")
+ end
+
+ -- Q2
+ local res, count, log =
+ db:find("parrots2", Q():F("likes"):Eq("toys"):OrderBy({ name = 1 }, { age = -1 }))
+ for i = 1, #res do -- iterate one
+ print("" .. res:field(i, "name") .. " likes toys #2")
+ end
+
+ -- Second way to iterate
+ for vobj, idx in res() do
+ print("" .. vobj["name"] .. " likes toys #3")
+ end
+
+ db:close()</pre>
+ </ul>
<h2><a href="#Functions">Functions</a></h2>
<td class="summary">Convenient <code>count(*)</code> operation.</td>
</tr>
<tr>
+ <td class="name" nowrap><a href="#DB:sync">DB:sync (cname)</a></td>
+ <td class="summary">Synchronize EJDB database with storage.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:getDBMeta">DB:getDBMeta ()</a></td>
+ <td class="summary">Get table object describes a database structure and its collections.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:beginTransaction">DB:beginTransaction (cname)</a></td>
+ <td class="summary">Begin collection transaction.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:commitTransaction">DB:commitTransaction (cname)</a></td>
+ <td class="summary">Commit collection transaction.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:rollbackTransaction">DB:rollbackTransaction (cname)</a></td>
+ <td class="summary">Rollback collection transaction.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:getTransactionStatus">DB:getTransactionStatus (cname)</a></td>
+ <td class="summary">Get collection transaction status.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:dropIndexes">DB:dropIndexes (cname, fpath)</a></td>
+ <td class="summary">DROP indexes of all types for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:optimizeIndexes">DB:optimizeIndexes (cname, fpath)</a></td>
+ <td class="summary">OPTIMIZE indexes of all types for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:ensureStringIndex">DB:ensureStringIndex (cname, fpath)</a></td>
+ <td class="summary">Ensure index presence of String type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:rebuildStringIndex">DB:rebuildStringIndex (cname, fpath)</a></td>
+ <td class="summary">Rebuild index of String type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:dropStringIndex">DB:dropStringIndex (cname, fpath)</a></td>
+ <td class="summary">Drop index of String type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:ensureIStringIndex">DB:ensureIStringIndex (cname, fpath)</a></td>
+ <td class="summary">Ensure case insensitive String index for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:rebuildIStringIndex">DB:rebuildIStringIndex (cname, fpath)</a></td>
+ <td class="summary">Rebuild case insensitive String index for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:dropIStringIndex">DB:dropIStringIndex (cname, fpath)</a></td>
+ <td class="summary">Drop case insensitive String index for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:ensureNumberIndex">DB:ensureNumberIndex (cname, fpath)</a></td>
+ <td class="summary">Ensure index presence of Number type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:rebuildNumberIndex">DB:rebuildNumberIndex (cname, fpath)</a></td>
+ <td class="summary">Rebuild index of Number type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:dropNumberIndex">DB:dropNumberIndex (cname, fpath)</a></td>
+ <td class="summary">Drop index of Number type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:ensureArrayIndex">DB:ensureArrayIndex (cname, fpath)</a></td>
+ <td class="summary">Ensure index presence of Array type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:rebuildArrayIndex">DB:rebuildArrayIndex (cname, fpath)</a></td>
+ <td class="summary">Rebuild index of Array type for JSON field path.</td>
+ </tr>
+ <tr>
+ <td class="name" nowrap><a href="#DB:rebuildArrayIndex">DB:rebuildArrayIndex (cname, fpath)</a></td>
+ <td class="summary">Drop index of Array type for JSON field path.</td>
+ </tr>
+ <tr>
<td class="name" nowrap><a href="#RS:object">RS:object (i)</a></td>
<td class="summary">Returns result set lua table object at specified position <code>i</code></td>
</tr>
<td class="summary">Length of result set.</td>
</tr>
<tr>
+ <td class="name" nowrap><a href="#Q:KV">Q:KV (key, value)</a></td>
+ <td class="summary">Adds field into current JSON object.</td>
+ </tr>
+ <tr>
<td class="name" nowrap><a href="#Q:F">Q:F (fname)</a></td>
<td class="summary">Set current field for the next operation during query building.</td>
</tr>
<ul>
<li><span class="parameter">cname</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
- Name of collection.</li>
+ Collection name.</li>
<li><span class="parameter">obj</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a> or <a class="type" href="index.html#Q">Q</a></span>
represents JSON object.</li>
<ul>
<li><span class="parameter">cname</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
- Name of collection</li>
+ Collection name</li>
<li><span class="parameter">q</span>
<span class="types"><a class="type" href="index.html#Q">Q</a></span>
JSON query object</li>
<ul>
<li><span class="parameter">cname</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
- Name of collection</li>
+ Collection name</li>
<li><span class="parameter">q</span>
<span class="types"><a class="type" href="index.html#Q">Q</a></span>
JSON query object</li>
<ul>
<li><span class="parameter">cname</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
- Name of collection</li>
+ Collection name</li>
<li><span class="parameter">q</span>
<span class="types"><a class="type" href="index.html#Q">Q</a></span>
JSON query object</li>
<ul>
<li><span class="parameter">cname</span>
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
- Name of collection</li>
+ Collection name</li>
<li><span class="parameter">q</span>
<span class="types"><a class="type" href="index.html#Q">Q</a></span>
JSON query object</li>
</dd>
<dt>
+ <a name = "DB:sync"></a>
+ <strong>DB:sync (cname)</strong>
+ </dt>
+ <dd>
+ Synchronize EJDB database with storage.
+ If <code>cname</code> is provided only this collection will be synced.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types">optional <a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:getDBMeta"></a>
+ <strong>DB:getDBMeta ()</strong>
+ </dt>
+ <dd>
+
+<p>Get table object describes a database structure and its collections. </p>
+
+<p> Sample meta:</p>
+
+<pre><code>collections = {
+ ecoll = {
+ file = "testdb_ecoll",
+ indexes = {},
+ name = "ecoll",
+ options = {
+ buckets = 425977,
+ cachedrecords = 0,
+ compressed = false,
+ large = true
+ },
+ records = 1
+ },
+ mycoll = {
+ file = "testdb_mycoll",
+ indexes = { {
+ field = "foo",
+ file = "testdb_mycoll.idx.sfoo.lex",
+ iname = "sfoo",
+ records = 3,
+ type = "lexical"
+ } },
+ name = "mycoll",
+ options = {
+ buckets = 131071,
+ cachedrecords = 0,
+ compressed = false,
+ large = false
+ },
+ records = 4
+ }
+},
+file = "testdb"
+</code></pre>
+
+
+
+
+ <h3>Returns:</h3>
+ <ol>
+
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
+ Database metadata
+ </ol>
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:beginTransaction"></a>
+ <strong>DB:beginTransaction (cname)</strong>
+ </dt>
+ <dd>
+ Begin collection transaction.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:commitTransaction"></a>
+ <strong>DB:commitTransaction (cname)</strong>
+ </dt>
+ <dd>
+ Commit collection transaction.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:rollbackTransaction"></a>
+ <strong>DB:rollbackTransaction (cname)</strong>
+ </dt>
+ <dd>
+ Rollback collection transaction.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:getTransactionStatus"></a>
+ <strong>DB:getTransactionStatus (cname)</strong>
+ </dt>
+ <dd>
+ Get collection transaction status.
+ Returns <code>True</code> if transaction is active.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ </ul>
+
+ <h3>Returns:</h3>
+ <ol>
+
+ <span class="types"><span class="type">bool</span></span>
+
+
+
+ </ol>
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:dropIndexes"></a>
+ <strong>DB:dropIndexes (cname, fpath)</strong>
+ </dt>
+ <dd>
+ DROP indexes of all types for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:optimizeIndexes"></a>
+ <strong>DB:optimizeIndexes (cname, fpath)</strong>
+ </dt>
+ <dd>
+ OPTIMIZE indexes of all types for JSON field path.
+ Performs B+ tree index file optimization.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:ensureStringIndex"></a>
+ <strong>DB:ensureStringIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Ensure index presence of String type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:rebuildStringIndex"></a>
+ <strong>DB:rebuildStringIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Rebuild index of String type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:dropStringIndex"></a>
+ <strong>DB:dropStringIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Drop index of String type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:ensureIStringIndex"></a>
+ <strong>DB:ensureIStringIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Ensure case insensitive String index for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:rebuildIStringIndex"></a>
+ <strong>DB:rebuildIStringIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Rebuild case insensitive String index for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:dropIStringIndex"></a>
+ <strong>DB:dropIStringIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Drop case insensitive String index for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:ensureNumberIndex"></a>
+ <strong>DB:ensureNumberIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Ensure index presence of Number type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:rebuildNumberIndex"></a>
+ <strong>DB:rebuildNumberIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Rebuild index of Number type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:dropNumberIndex"></a>
+ <strong>DB:dropNumberIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Drop index of Number type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:ensureArrayIndex"></a>
+ <strong>DB:ensureArrayIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Ensure index presence of Array type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:rebuildArrayIndex"></a>
+ <strong>DB:rebuildArrayIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Rebuild index of Array type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
+ <a name = "DB:rebuildArrayIndex"></a>
+ <strong>DB:rebuildArrayIndex (cname, fpath)</strong>
+ </dt>
+ <dd>
+ Drop index of Array type for JSON field path.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">cname</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ Collection name</li>
+ <li><span class="parameter">fpath</span>
+ <span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
+ JSON field path for index</li>
+ </ul>
+
+
+
+
+
+</dd>
+ <dt>
<a name = "RS:object"></a>
<strong>RS:object (i)</strong>
</dt>
</dd>
<dt>
+ <a name = "Q:KV"></a>
+ <strong>Q:KV (key, value)</strong>
+ </dt>
+ <dd>
+ Adds field into current JSON object.
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">key</span>
+
+
+</li>
+ <li><span class="parameter">value</span>
+
+
+</li>
+ </ul>
+
+
+
+
+ <h3>Usage:</h3>
+ <ul>
+ <pre class="example">Q():KV(<span class="string">"foo"</span>, <span class="string">"bar"</span>):KV(<span class="string">"age"</span>, <span class="number">30</span>) => {<span class="string">"foo"</span> : <span class="string">"bar"</span>, <span class="string">"age"</span> : <span class="number">30</span>}</pre>
+ </ul>
+
+</dd>
+ <dt>
<a name = "Q:F"></a>
<strong>Q:F (fname)</strong>
</dt>
<h3>see also:</h3>
<ul>
+ <li><a href="index.html#Q:KV">Q:KV</a></li>
<li><a href="index.html#Q:F">Q:F</a></li>
<li><a href="index.html#Q:Eq">Q:Eq</a></li>
<li><a href="index.html#Q:ElemMatch">Q:ElemMatch</a></li>
--- The Lua binding of EJDB database.<br/>
-- <a href="http://ejdb.org">http://ejdb.org</a>
+-- @usage
+-- -- File: samples/sample1.lua
+--
+-- local ejdb = require("ejdb")
+-- local inspect = require("ejdb.inspect")
+-- local Q = ejdb.Q
+--
+-- -- Used modes:
+-- -- 'r' - read
+-- -- 'w' - write
+-- -- 'c' - create db if not exists
+-- -- 't' - truncate existing db
+-- local db = ejdb.open("zoo", "rwct")
+--
+-- -- Unordered lua table
+-- local parrot1 = {
+-- name = "Grenny",
+-- type = "African Grey",
+-- male = true,
+-- age = 1,
+-- birthhdate = ejdb.toDateNow(),
+-- likes = { "green color", "night", "toys" },
+-- extra1 = ejdb.toNull()
+-- }
+--
+-- -- Preserve order of BSON keys
+-- local parrot2 = Q();
+-- parrot2:KV("name", "Bounty"):KV("type", "Cockatoo"):KV("male", false)
+-- parrot2:KV("age", 15):KV("birthdate",
+-- ejdb.toDate({ year = 2013, month = 1, day = 1,
+-- hour = 0, sec = 1 }))
+-- parrot2:KV("likes", { "sugar cane" }):KV("extra1", ejdb.toNull())
+--
+-- --IF YOU WANT SOME DATA INSPECTIONS:
+-- --print(ejdb.print_bson(parrot2:toBSON()))
+-- --local obj = ejdb.from_bson(parrot2:toBSON())
+-- --print(inspect(obj));
+--
+-- db:save("parrots2", parrot1)
+-- db:save("parrots2", parrot2)
+--
+-- -- Below two equivalent queries:
+-- -- Q1
+-- local res, count, log =
+-- db:find("parrots2", Q("likes", "toys"):OrderBy("name asc", "age desc"))
+-- for i = 1, #res do -- iterate one
+-- local ob = res:object(i)
+-- print("" .. ob["name"] .. " likes toys #1")
+-- end
+--
+-- -- Q2
+-- local res, count, log =
+-- db:find("parrots2", Q():F("likes"):Eq("toys"):OrderBy({ name = 1 }, { age = -1 }))
+-- for i = 1, #res do -- iterate one
+-- print("" .. res:field(i, "name") .. " likes toys #2")
+-- end
+--
+-- -- Second way to iterate
+-- for vobj, idx in res() do
+-- print("" .. vobj["name"] .. " likes toys #3")
+-- end
+--
+-- db:close()
module("ejdb")
-- @usage Q("likes", "toys"):OrderBy("name asc", "age desc")
-- @usage Q("name", "Andy"):F("_id"):Eq("510f7fa91ad6270a00000000"):F("age"):Gt(20):Lt(40):F("score"):In({ 11, 22.12333, 1362835380447, db.toNull() }):Max(232)
-- @usage Q():Or(Q("foo", "bar"), Q("foo", "bar6")):OrderBy({ foo = 1 })
+-- @see Q:KV
-- @see Q:F
-- @see Q:Eq
-- @see Q:ElemMatch
-- Each persistent object has unique identifier (OID) placed in the `_id` property.
-- If a saved object does not have `_id` it will be autogenerated.
-- To identify and update object it should contains `_id` property.
--- @tparam string cname Name of collection.
+-- @tparam string cname Collection name.
-- @tparam table|Q obj represents JSON object.
-- @param ... If last argument is True a saved object will be merged with who's
-- already persisted in db.
-- end
--
--
--- @tparam string cname Name of collection
+-- @tparam string cname Collection name
-- @tparam Q q JSON query object
-- @string flags Query control flags:
-- `c`: only count of matching records will be returned without placing records in result set.
function DB:find(cname, q, flags) end
--- Same as @{DB:find} but retrieves only first matching JSON object.
--- @tparam string cname Name of collection
+-- @tparam string cname Collection name
-- @tparam Q q JSON query object
-- @treturn table Lua table constructed from matched BSON record or `nil` of record not found
-- @treturn number Count of matched/updated records
function DB:findOne(cname, q, ...) end
--- Convenient method to execute update queries.
--- @tparam string cname Name of collection
+-- @tparam string cname Collection name
-- @tparam Q q JSON query object
-- @treturn number Count of matched/updated records
-- @treturn ?string Query execution log if `l` flag presented in the control `flags`
function DB:update(cname, q, ...) end
--- Convenient `count(*)` operation.
--- @tparam string cname Name of collection
+-- @tparam string cname Collection name
-- @tparam Q q JSON query object
-- @treturn number Count of matched/updated records
-- @treturn ?string Query execution log if `l` flag presented in the control `flags`
function DB:count(cname, q, ...) end
+--- Synchronize EJDB database with storage.
+-- If `cname` is provided only this collection will be synced.
+-- @tparam ?string cname Collection name
+function DB:sync(cname) end
+
+
+--- Get table object describes a database structure and its collections.
+--
+-- Sample meta:
+--
+-- collections = {
+-- ecoll = {
+-- file = "testdb_ecoll",
+-- indexes = {},
+-- name = "ecoll",
+-- options = {
+-- buckets = 425977,
+-- cachedrecords = 0,
+-- compressed = false,
+-- large = true
+-- },
+-- records = 1
+-- },
+-- mycoll = {
+-- file = "testdb_mycoll",
+-- indexes = { {
+-- field = "foo",
+-- file = "testdb_mycoll.idx.sfoo.lex",
+-- iname = "sfoo",
+-- records = 3,
+-- type = "lexical"
+-- } },
+-- name = "mycoll",
+-- options = {
+-- buckets = 131071,
+-- cachedrecords = 0,
+-- compressed = false,
+-- large = false
+-- },
+-- records = 4
+-- }
+-- },
+-- file = "testdb"
+--
+-- @treturn table Database metadata
+function DB:getDBMeta() end
+
+--- Begin collection transaction.
+-- @tparam string cname Collection name
+function DB:beginTransaction() end
+
+--- Commit collection transaction.
+-- @tparam string cname Collection name
+function DB:commitTransaction() end
+
+--- Rollback collection transaction.
+-- @tparam string cname Collection name
+function DB:rollbackTransaction() end
+
+--- Get collection transaction status.
+-- Returns `True` if transaction is active.
+-- @tparam string cname Collection name
+-- @treturn bool
+function DB:getTransactionStatus() end
+
+--- DROP indexes of all types for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:dropIndexes(cname, fpath) end
+
+--- OPTIMIZE indexes of all types for JSON field path.
+-- Performs B+ tree index file optimization.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:optimizeIndexes(cname, fpath) end
+
+--- Ensure index presence of String type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:ensureStringIndex(cname, fpath) end
+
+--- Rebuild index of String type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:rebuildStringIndex(cname, fpath) end
+
+--- Drop index of String type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:dropStringIndex(cname, fpath) end
+
+--- Ensure case insensitive String index for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:ensureIStringIndex(cname, fpath) end
+
+--- Rebuild case insensitive String index for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:rebuildIStringIndex(cname, fpath) end
+
+--- Drop case insensitive String index for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:dropIStringIndex(cname, fpath) end
+
+--- Ensure index presence of Number type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:ensureNumberIndex(cname, fpath) end
+
+--- Rebuild index of Number type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:rebuildNumberIndex(cname, fpath) end
+
+--- Drop index of Number type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:dropNumberIndex(cname, fpath) end
+
+--- Ensure index presence of Array type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:ensureArrayIndex(cname, fpath) end
+
+--- Rebuild index of Array type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:rebuildArrayIndex(cname, fpath) end
+
+--- Drop index of Array type for JSON field path.
+-- @string cname Collection name
+-- @string fpath JSON field path for index
+function DB:rebuildArrayIndex(cname, fpath) end
--- Returns result set lua table object at specified position `i`
-- @tparam number i Position of record in the result set
-- @treturn table Resulting lua object constructed from BSON record.
function RS:object(i) end
-
--- Returns field value of lua object at specified position `i`
-- @tparam number i Position of record in the result set
-- @tparam string name JSON field name
function RS.__len() end
+--- Adds field into current JSON object.
+-- @usage Q():KV("foo", "bar"):KV("age", 30) => {"foo" : "bar", "age" : 30}
+function Q:KV(key, value) end
+
--- Set current field for the next operation during query building.
-- @string fname JSON field path
-- @usage Q:F("name"):Eq("andy"):F("age"):Gt(30) => {"name" : "andy", "age" : {"$gt" : 30}}