2. Get Started

2.1 Download ActorDB

Download ActorDB

If you are on OSX then open terminal and move into the directory where you downloaded the package above (*.tar.gz package) and run:

tar -zxvf actordb*.tar.gz

If you are on Ubuntu/Debian open terminal and move into the directory where you downloaded the package above (*.deb package) and run:

dpkg -i actordb*.deb

2.2 Run ActorDB

Let's assume we just wan't to test ActorDB and we won't do any configurational changes. Our ActorDB server is one node only and runs on host 127.0.0.1 and port 33306. Let's run ActorDB for the first time!

If on OSX move into directory:

cd actordb-*
            

and now run:

 ./bin/actordb start
 ./bin/actordb_console -f etc/init.example.sql

If on Linux:

 actordb start
 actordb_console -f /etc/init.example.sql

Once actordb_console is finished running (should be quick), you have an initialized ActorDB setup. You should take a look at the init.example.sql file. It contains clustering settings, user accounts and schema.

2.3 Simple insert and query data

Queries to ActorDB can be executed using actordb_console. You can run actordb_console -h to print call options. If connecting to local node that is using default thrift interface port, IP can be omitted.

actordb_console -u myuser -pw mypass 127.0.0.1 

You should now be connected to ActorDB. You can connect without -pw (password), in that case you will be prompted for it. Next, run this command:

actordb> ACTOR type1(music) CREATE; 
actordb (1)> INSERT INTO tab (i,txt) VALUES (42,"this is our first run");
actordb (2)> c
Rowid: 1, Rows changed: 1

Our actor instance is called 'music' and it has schema of type1 (set in init.sql). If this instance doesn't exist it will be created after first query because it has the CREATE flag. Run:

actordb> ACTOR type1(music); SELECT * FROM tab;
actordb (1) c
*****************************
i  id txt                   |
-----------------------------
42 1  this is our first run |
-----------------------------

2.4 CRUD in ActorDB

2.4.1 Create

Let's start with creating some instances of actors type1 and inserting data.

actordb> ACTOR type1(sport) CREATE;
actordb (1)> INSERT INTO tab (i,txt) VALUES (1,"Insert into sport.");
actordb (2)> ACTOR type1(reading) CREATE;
actordb (3)> INSERT INTO tab (i,txt) VALUES (2,"Insert into reading.");
actordb (4)> ACTOR type1(paint) CREATE;
actordb (5)> INSERT INTO tab (i,txt) VALUES (3,"Insert into paint.");
actordb (6)> c
Rowid: 0, Rows changed: 3

The above was actually a 3 actor transaction. Here is another one:

actordb> ACTOR type1(sport,reading,paint);
actordb (1)> INSERT INTO tab (i,txt) VALUES (2,"Insert into three type1 actors.");
actordb (2)> c
Rowid: 0, Rows changed: 3

Lets read tab from all actors of type1:

actordb> actor type1(*); {{RESULT}}select * from tab;
actordb (1)> c
***********************************************
actor   i  id txt                             |
-----------------------------------------------
sport   1  1  Insert into sport.              |
sport   2  2  Insert into three type1 actors. |
paint   3  1  Insert into paint.              |
paint   2  2  Insert into three type1 actors. |
reading 2  1  Insert into reading.            |
reading 2  2  Insert into three type1 actors. |
music   42 1  this is our first run           |
-----------------------------------------------

2.4.2 Reading actors and tables

If you followed this tutorial from step 1 to 4, you should have four actors of type1. Let's check this assumption with next query:

actordb> ACTOR type1(*);PRAGMA list;
actordb (1)> c
*********
actor   |
---------
sport   |
paint   |
reading |
music   |
---------

2.4.3 Updating tables in actors

We can update actor by actor or all actors at once. Let's start with only one actor:

actordb> ACTOR type1(music); SELECT * FROM tab;
actordb (1)> c
*****************************
i  id txt                   |
-----------------------------
42 1  this is our first run |
----------------------------- 
actordb> ACTOR type1(music);
actordb (1)> UPDATE tab SET i=i+1 WHERE id=1;
actordb (2)> c
Rowid: 9, Rows changed: 1
actordb> ACTOR type1(music); SELECT * FROM tab;
actordb (1)> c
*****************************
i  id txt                   |
-----------------------------
43 1  this is our first run |
-----------------------------

Let's update all four actors at once. Begin with selecting all actors of type type1. Note this is just an example, you really should not have queries like this in production. Transactions over many actors are not cheap:

actordb> ACTOR type1(*);
actordb (1)> UPDATE tab SET i=44 WHERE id = 1;
actordb (2)> c
Rowid: 0, Rows changed: 4
actordb> actor type1(*); {{RESULT}}select * from tab;
actordb (1)> c
***********************************************
actor   i  id txt                             |
-----------------------------------------------
sport   44 1  Insert into sport.              |
sport   2  2  Insert into three type1 actors. |
paint   44 1  Insert into paint.              |
paint   2  2  Insert into three type1 actors. |
reading 44 1  Insert into reading.            |
reading 2  2  Insert into three type1 actors. |
music   44 1  this is our first run           |
---------------------------------------------

All tables tab in all actors now have column i of value 44.

2.4.4 Deleting tables in actors and actors itself

Deleting a row in actor music and table tab:

actordb> ACTOR type1(music);
actordb (1)> DELETE FROM tab WHERE id=1;
actordb (2)> c
actordb> ACTOR type1(music);
actordb (1)> select * from tab;
actordb (2)> c
No results.

Deleting a specific row in table tab in all actors of type type1.

actordb> ACTOR type1(*);
actordb (1)> DELETE FROM tab WHERE id=2;
actordb (2)> c
Rowid: 0, Rows changed: 4
actordb> ACTOR type1(*);
actordb (1)> {{RESULT}}select * from tab;
actordb (2)> c
************************************
actor   i  id txt                  |
------------------------------------
sport   44 1  Insert into sport.   |
paint   44 1  Insert into paint.   |
reading 44 1  Insert into reading. |
------------------------------------

We can also delete all our actors. Proceed with caution!

actordb> ACTOR type1(*);
actordb (1)> PRAGMA delete; 
actordb (2)> c
Rowid: 0, Rows changed: 4
actordb> ACTOR type1(*);
actordb (1)> pragma list;
actordb (2)> c
No results.

2.5 Cleanup

You can reset ActorDB back to uninitialized state by first shutting it down using: actordb stop. Then deleting the lmdb file. On linux this is: /var/lib/actordb/. On osx/windows this is: ./data/

<< Previous     (1. About) (3. How it works)     Next >>