Skip to content
HouzuoGuo edited this page Apr 14, 2013 · 6 revisions

Tutorial

Please make sure to install dependencies:

  • JDK 7+
  • Scala 2.10+
  • SBT 0.12.0+

The tutorial assumes that you are using Linux/UNIX operating system.

Below command responses are indicated by "> ".

Get Aurinko2

git clone git://github.com/HouzuoGuo/Aurinko2.git
git checkout alpha
cd Aurinko2
sbt test # run all test cases

You may need to increase JVM heap size for SBT to run all test cases. They all should pass.

If you have trouble setting SBT JVM heap size, this guide may help you.

Run server, connect client

Run server
CLI options: port_number database_path
sbt "run 1993 /tmp/tutorial_db"
Connect client
telnet localhost 1993

Collection management

Create collection
<create col="os"/>
<go/>
> <ok/>

<create col="os2"/>
<go/>
> <ok/>
Rename collection
<rename col="os2" to="to_be_deleted"/>
<go/>
> <ok/>
Show all collections
<all/>
<go/>
> <r><col>to_be_deleted</col><col>os</col></r>
> <ok/>
Drop collection
<drop col="to_be_deleted"/>
<go/>
> <ok/>
Repair collection from severe data corruption

OR recover space from deleted douments
<repair col="os"/>
<go/>
> <ok/>
Shutdown server
<shutdown/>
<go/>
> <ok/>

Document management

Insert document

Server responds with document unique ID
<insert col="os">
    <linux>
        <name>Slackware</name>
        <release>
            <initial>1993</initial>
            <latest>2012</latest>
        </release>
    </linux>
</insert>
<go/>
> <r>0</r>
> <ok/>

<insert col="os">
    <linux>
        <name>OpenSUSE</name>
        <release>
            <initial>2006</initial>
            <latest>2013</latest>
        </release>
    </linux>
</insert>
<go/>
> <r>482</r>
> <ok/>

<insert col="os">
    <UNIX>
        <name>Solaris</name>
        <release>
            <initial>1992</initial>
            <latest>2012</latest>
        </release>
    </UNIX>
</insert>
<go/>
> <r>961</r>
> <ok/>
Get all documents
> <r>
<doc id="0">
<linux><name>Slackware</name>
<release><initial>1993</initial><latest>2012</latest></release></linux>
</doc>
<doc id="482">
<linux><name>OpenSUSE</name>
<release><initial>2006</initial><latest>2013</latest></release></linux>
</doc>
<doc id="961">
<UNIX><name>Solaris</name>
<release><initial>1992</initial><latest>2012</latest></release></UNIX>
</doc></r>
> <ok/>
Update document

Server responds with new ID of the document (not always the same as original ID)
<update col="os" id="961">
<UNIX>
    <name>Solaris</name>
    <release>
        <initial>1992</initial>
        <latest>2012</latest>
    </release>
    <vendor>Oracle</vendor>
</UNIX>
</update>
<go/>
> <r><old>961</old><new>961</new></r>
> <ok/>
Delete document
<delete col="os" id="1234"/>
<go/>
> <err>Document 1234 does not exist</err>
> <ok/>
Create index
<hash-index col="os">
    <path>name</path>
</hash-index>
<go/>
> <ok/>

<hash-index col="os">
    <path>release</path>
    <path>latest</path>
</hash-index>
<go/>
> <ok/>
Show all indexes
<indexed col="os"/>
<go/>
> <r> <index type="hash" hash-bits="12" bucket-size="100"> <path>
    </path><path>name</path><path>
</path></index><index type="hash" hash-bits="12" bucket-size="100"> <path>
    </path><path>release</path><path>
    </path><path>latest</path><path>
</path></index></r>
> <ok/>
Drop index
<drop-index col="os">
    <path>release</path>
    <path>latest</path>
</drop-index>
<go/>
> <ok/>

Query

There is a number of query result options:

Document ID
<q col={ collection }>{ conditions }</q>
Document ID and content
<select col={ collection }>{ conditions }</select>
Count of documents
<count col={ collection }>{ conditions }</count>

Conditions are evaluated in the following order: first to last, outter to inner.

Conditions

Lookup
<eq>
    <to>{ value }</to>
    <in>
        <path>{ Node name 1 }</path>
        <path>{ Node name 2 }</path>...
    </in>
</eq>
Value exists
<has>
    <path>{ Node name 1 }</path>
    <path>{ Node name 2 }</path>...
</has>
All documents
<all/>
Intersection
<intersect>
    { Condition 1 }
    { Condition 2 }...
</intersect>
Difference
<diff>
    { Condition 1 }
    { Condition 2 }...
</has>

All of the conditions may take optional skip and limit attributes.

Examples

Which OS does not have a latest release in 2012?
<select col="os">
    <diff>
        <all/>
        <eq>
            <to><latest>2012</latest></to>
            <in>
                <path>release</path>
                <path>latest</path>
            </in>
        </eq>
    </diff>
</select>
<go/>
> <r><doc id="482"><linux><name>OpenSUSE</name>
<release><initial>2006</initial><latest>2013</latest></release></linux>
</doc></r>
> <ok/>
Which OS has a latest release in 2012, and was initially released in 1993?
<select col="os">
    <intersect>
        <eq>
            <to><latest>2012</latest></to>
            <in>
                <path>release</path>
                <path>latest</path>
            </in>
        </eq>
        <eq>
            <to><initial>1993</initial></to>
            <in>
                <path>release</path>
                <path>initial</path>
            </in>
        </eq>
    </intersect>
</select>
<go/>
> <r><doc id="0"><linux><name>Slackware</name>
<release><initial>1993</initial><latest>2012</latest></release></linux>
</doc></r>
> <ok/>
Give me 2nd and 3rd documents
<select col="os">
    <all skip="1" limit="2"/>
</select>
<go/>
> <r><doc id="482"><linux><name>OpenSUSE</name>
<release><initial>2006</initial><latest>2013</latest></release>
</linux></doc>
<doc id="961"><UNIX><name>Solaris</name>
<release><initial>1992</initial><latest>2012</latest></release>
<vendor>Oracle</vendor></UNIX></doc></r>
> <ok/>

Any question?

Email me, I will be very glad to help you!