biokoda / actordb

ActorDB distributed SQL database
Mozilla Public License 2.0
1.9k stars 71 forks source link

How to inspect database structure? #46

Closed catroot closed 7 years ago

catroot commented 7 years ago

Is there a way to query an actor for table names? Is this a proper way to list tables under filesystem actor? :

actor filesystem(*);
SELECT name FROM sqlite_master WHERE type='table';

I get no results from this query, however, in init.sql i have a rows:

actor filesystem kv
CREATE TABLE actors (id TEXT PRIMARY KEY, hash INTEGER, size INTEGER)  WITHOUT ROWID
CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, fileid TEXT, uid INTEGER, FOREIGN KEY (fileid) REFERENCES actors(id) ON DELETE CASCADE)

And i expect to see those tables somehow.

How to use something like PRAGMA table_info([tablename]); if this works in actordb?

SergejJurecko commented 7 years ago

What are you using to connect to ActorDB?

catroot commented 7 years ago

actordb_console -u root

actordb> s
****************************************************************************************************************************************************************
sql                                                                                                                                                 type       |
----------------------------------------------------------------------------------------------------------------------------------------------------------------
$CREATE TABLE tab (id INTEGER PRIMARY KEY, txt TEXT);                                                                                               type1      |
$CREATE TABLE tab1 (id INTEGER PRIMARY KEY, txt TEXT);                                                                                              type1      |
$ALTER TABLE tab ADD i INTEGER;                                                                                                                     type1      |
$CREATE TABLE tabx (id INTEGER PRIMARY KEY CHECK (typeof(id) == 'integer'), txt TEXT CHECK (typeof(id) == 'text'));                                 type1      |
$CREATE TABLE asdf (id INTEGER PRIMARY KEY AUTOINCREMENT, txt BLOB);                                                                                type2      |
$CREATE TABLE actors (id TEXT PRIMARY KEY, hash INTEGER, val INTEGER) WITHOUT ROWID;                                                                counters   |
$CREATE TABLE actors (id TEXT PRIMARY KEY, hash INTEGER, size INTEGER)  WITHOUT ROWID;                                                              filesystem |
$CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, fileid TEXT, uid INTEGER, FOREIGN KEY (fileid) REFERENCES actors(id) ON DELETE CASCADE); filesystem |
----------------------------------------------------------------------------------------------------------------------------------------------------------------

PS i've got this work:

actordb> actor type1(test) create;
actordb (1)> SELECT name FROM sqlite_master WHERE type='table';
actordb (2)> c
****************
name           |
----------------
__transactions |
__adb          |
tab            |
tab1           |
tabx           |
----------------

And this:

actordb> actor type1(test) create;
actordb (1)> PRAGMA table_info([tab]);
actordb (2)> c
****************************************
cid dflt_value name notnull pk type    |
----------------------------------------
0   null       id   0       1  INTEGER |
1   null       txt  0       0  TEXT    |
2   null       i    0       0  INTEGER |
----------------------------------------
SergejJurecko commented 7 years ago

The thrift interface has functions: actor_types, actor_tables, actor_columns

For the SQL interface, the correct query is:

actor filesystem(1);
SELECT name FROM sqlite_master WHERE type='table';

setting * for actor name means running query across all shards (multi actor query). Setting it to 1 (or any simple word) will mean sending query to a single shard.

Multi actor queries require {{RESULT}} variable. Running this:

actor filesystem(*);
{{RESULT}}SELECT name FROM sqlite_master WHERE type='table';

Will return a much bigger result and have an additional column "actor".

catroot commented 7 years ago

Thank you.