working on luadoc
authoradam <adamansky@gmail.com>
Wed, 20 Mar 2013 11:27:03 +0000 (18:27 +0700)
committeradam <adamansky@gmail.com>
Wed, 20 Mar 2013 11:27:03 +0000 (18:27 +0700)
luaejdb/doc/index.html
luaejdb/ejdb.luadoc
luaejdb/test/t1.lua

index fb6e468..b21654f 100644 (file)
 <p>
 
 </p>
+    <h3>Usage:</h3>
+    <ul>
+        <pre class="example">
+ -- File: samples/sample1.lua
+
+  local ejdb = require(&quot;ejdb&quot;)
+  local inspect = require(&quot;ejdb.inspect&quot;)
+  local Q = ejdb.Q
+
+  -- Used modes:
+  -- &apos;r&apos; - read
+  -- &apos;w&apos; - write
+  -- &apos;c&apos; - create db if not exists
+  -- &apos;t&apos; - truncate existing db
+  local db = ejdb.open(&quot;zoo&quot;, &quot;rwct&quot;)
+
+  -- Unordered lua table
+  local parrot1 = {
+    name = &quot;Grenny&quot;,
+    type = &quot;African Grey&quot;,
+    male = true,
+    age = 1,
+    birthhdate = ejdb.toDateNow(),
+    likes = { &quot;green color&quot;, &quot;night&quot;, &quot;toys&quot; },
+    extra1 = ejdb.toNull()
+  }
+
+  -- Preserve order of BSON keys
+  local parrot2 = Q();
+  parrot2:KV(&quot;name&quot;, &quot;Bounty&quot;):KV(&quot;type&quot;, &quot;Cockatoo&quot;):KV(&quot;male&quot;, false)
+  parrot2:KV(&quot;age&quot;, 15):KV(&quot;birthdate&quot;,
+                        ejdb.toDate({ year = 2013, month = 1, day = 1,
+                                      hour = 0, sec = 1 }))
+  parrot2:KV(&quot;likes&quot;, { &quot;sugar cane&quot; }):KV(&quot;extra1&quot;, 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(&quot;parrots2&quot;, parrot1)
+  db:save(&quot;parrots2&quot;, parrot2)
+
+  -- Below two equivalent queries:
+  -- Q1
+  local res, count, log =
+  db:find(&quot;parrots2&quot;, Q(&quot;likes&quot;, &quot;toys&quot;):OrderBy(&quot;name asc&quot;, &quot;age desc&quot;))
+  for i = 1, #res do -- iterate one
+    local ob = res:object(i)
+    print(&quot;&quot; .. ob[&quot;name&quot;] .. &quot; likes toys #1&quot;)
+  end
+
+  -- Q2
+  local res, count, log =
+  db:find(&quot;parrots2&quot;, Q():F(&quot;likes&quot;):Eq(&quot;toys&quot;):OrderBy({ name = 1 }, { age = -1 }))
+  for i = 1, #res do -- iterate one
+    print(&quot;&quot; .. res:field(i, &quot;name&quot;) .. &quot; likes toys #2&quot;)
+  end
+
+  -- Second way to iterate
+  for vobj, idx in res() do
+    print(&quot;&quot; .. vobj[&quot;name&quot;] .. &quot; likes toys #3&quot;)
+  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&nbsp;(cname)</a></td>
+       <td class="summary">Synchronize EJDB database with storage.</td>
+       </tr>
+       <tr>
+       <td class="name" nowrap><a href="#DB:getDBMeta">DB:getDBMeta&nbsp;()</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&nbsp;(cname)</a></td>
+       <td class="summary">Begin collection transaction.</td>
+       </tr>
+       <tr>
+       <td class="name" nowrap><a href="#DB:commitTransaction">DB:commitTransaction&nbsp;(cname)</a></td>
+       <td class="summary">Commit collection transaction.</td>
+       </tr>
+       <tr>
+       <td class="name" nowrap><a href="#DB:rollbackTransaction">DB:rollbackTransaction&nbsp;(cname)</a></td>
+       <td class="summary">Rollback collection transaction.</td>
+       </tr>
+       <tr>
+       <td class="name" nowrap><a href="#DB:getTransactionStatus">DB:getTransactionStatus&nbsp;(cname)</a></td>
+       <td class="summary">Get collection transaction status.</td>
+       </tr>
+       <tr>
+       <td class="name" nowrap><a href="#DB:dropIndexes">DB:dropIndexes&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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>
@@ -832,7 +982,7 @@ end
     <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>
@@ -885,7 +1035,7 @@ end
     <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>
@@ -919,7 +1069,7 @@ end
     <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>
@@ -950,7 +1100,7 @@ end
     <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>
@@ -971,6 +1121,479 @@ end
 
 </dd>
     <dt>
+    <a name = "DB:sync"></a>
+    <strong>DB:sync&nbsp;(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&nbsp;()</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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(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&nbsp;(i)</strong>
     </dt>
@@ -1036,6 +1659,34 @@ end
 
 </dd>
     <dt>
+    <a name = "Q:KV"></a>
+    <strong>Q:KV&nbsp;(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>) =&gt; {<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&nbsp;(fname)</strong>
     </dt>
@@ -1924,6 +2575,7 @@ end
 
     <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>
index d0e3022..8b9b54c 100644 (file)
@@ -1,5 +1,68 @@
 --- 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")
 
@@ -16,6 +79,7 @@ local 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
@@ -176,7 +240,7 @@ function DB.toUndefined() end
 -- 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.
@@ -306,7 +370,7 @@ function DB:save(cname, obj, ...) end
 --    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.
@@ -323,7 +387,7 @@ function DB:save(cname, obj, ...) end
 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
@@ -332,7 +396,7 @@ function DB:find(cname, q, flags) end
 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`
@@ -340,20 +404,154 @@ function DB:findOne(cname, q, ...) end
 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
@@ -364,6 +562,10 @@ function RS:field(i, name) end
 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}}
index 59d2dcb..175e9dc 100644 (file)
@@ -207,7 +207,7 @@ assert(db:count("ecoll", Q():F("k2", 2):F("k3", 0)) == 1)
 
 db:ensureStringIndex("mycoll", "foo")
 
-print(ejdb.print_bson(Q():F("tags"):AddToSetAll({"red", "green"}):toBSON()))
+--print(ejdb.print_bson(Q():F("tags"):AddToSetAll({"red", "green"}):toBSON()))
 --print(inspect(db:getDBMeta()))
 
 db:dropCollection("ecoll", true);