Hello CrateΒΆ

To get started let’s have a quick look on how Crate Data can be used. This tutorial uses the crash command-line SQL shell shipped with Crate.

First lets connect to a running node:

cr> connect 127.0.0.1:4200;
+------------------------+-----------+-----------+---------+
| server_url             | node_name | connected | message |
+------------------------+-----------+-----------+---------+
| http://127.0.0.1:...   | crate     | TRUE      | OK      |
+------------------------+-----------+-----------+---------+
CONNECT OK

In this guide we want to create a database for Twitter tweets. Let’s create the table tweets with all columns we need. In order to keep this tutorial simple, we’ll just inserting the user_id instead of a complete user object:

cr> create table tweets (
...   created_at timestamp,
...   id string primary key,
...   retweeted boolean,
...   source string INDEX using fulltext,
...   text string INDEX using fulltext,
...   user_id string
... );
CREATE OK (... sec)

Now we are ready for inserting our first tweet:

cr> insert into tweets values(1394182937, '1', true, 'web', 'Don''t panic', 'Douglas');
INSERT OK, 1 row affected (... sec)

And another:

cr> insert into tweets values(1394182938, '2', true, 'web', 'Time is an illusion. Lunchtime doubly so', 'Ford');
INSERT OK, 1 row affected (... sec)

Looking up only Ford’s tweets:

cr> select * from tweets where id = '2';
+------------+----+-----------+--------+------------------------------------------+---------+
| created_at | id | retweeted | source | text                                     | user_id |
+------------+----+-----------+--------+------------------------------------------+---------+
| 1394182938 | 2  | TRUE      | web    | Time is an illusion. Lunchtime doubly so | Ford    |
+------------+----+-----------+--------+------------------------------------------+---------+
SELECT 1 row in set (... sec)