forked from discoproject/discodb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from bauman/dan
[DDB-15] [DDB-16]
- Loading branch information
Showing
13 changed files
with
658 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
|
||
.. cnf: | ||
cnf -- Query Language | ||
cnf -- Conjunctive Normal Form (used by Query Language) | ||
==================================================================== | ||
|
||
Both the Python API and C API will interpret CNF based queries to access values | ||
Both the Python API and C API will interpret CNF based queries into a normalized form for queries. | ||
|
||
|
||
|
||
.. code-block:: python | ||
>>> Q.parse('~(B | C)') == Q.parse('~B & ~C') | ||
True | ||
>>> Q.parse('(A & B) | C') == Q.parse('(A | C) & (B | C)') | ||
True | ||
>>> Q.parse('A & (B | (D & E))') == Q.parse('A & (B | D) & (B | E)') | ||
True | ||
>>> Q.parse(str(Q.parse('a | b | c & d | e'))) == Q.parse('a | b | c & d | e') | ||
True | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
.. luaapi: | ||
luaapi -- Lua library to read/write DiscoDBs | ||
==================================================================== | ||
|
||
The lua API links against libdiscodb at runtime and provides a thin wrapper to the functionality. | ||
|
||
This api is currently **read only** | ||
|
||
The following examples demonstrate a prebuilt ddb obtained using | ||
|
||
.. code-block:: bash | ||
wget http://pkgs.bauman.space/discodb/myths.ddb -O /tmp/myths.ddb` | ||
Examples | ||
======== | ||
Basic discodb wrapper for Lua. | ||
libdiscodb.so should be in :code:`LD_LIBRARY_PATH` | ||
Open and list keys | ||
------------------ | ||
.. code-block:: lua | ||
local ffi = require("ffi") | ||
local ddblib = ffi.load("libdiscodb.so", true) -- Load lib into global | ||
local discodb = require("discodb") | ||
local db = discodb.open("/tmp/myths.ddb") | ||
local iter = db:keys() | ||
for i = 1,#iter do | ||
print(i, iter:next()) | ||
end | ||
Open and get individual key | ||
--------------------------- | ||
.. code-block:: lua | ||
local ffi = require("ffi") | ||
local ddblib = ffi.load("libdiscodb.so", true) -- Load lib into global | ||
local discodb = require("discodb") | ||
local db = discodb.open("/tmp/myths.ddb") | ||
local iter = db:get("Major") | ||
for i = 1,#iter do | ||
print(i, iter:next()) | ||
end | ||
Check Key Exists Before Accessing | ||
--------------------------------- | ||
Depends on the control flow of choice. | ||
Either handle the error of attempting to access :code:`next()` on a nil iter | ||
or check iter is not nil before calling :code:`next()` on it. | ||
.. code-block:: lua | ||
local ffi = require("ffi") | ||
local ddblib = ffi.load("libdiscodb.so", true) -- Load lib into global | ||
local discodb = require("discodb") | ||
local db = discodb.open("/tmp/myths.ddb") | ||
local iter = db:get("Major") | ||
iter = db:get("key-should-not-exist") | ||
if iter then | ||
for i = 1,#iter do | ||
print(i, iter:next()) | ||
end | ||
else | ||
print("key does not exist") | ||
end | ||
Oops, something went wrong.