Search code examples
javascriptdatabaserethinkdbdeepstream.io

Create RethinkDB table on first getRecord in deepstream.io


I have a deepstream server connected to RethinkDB with the official connector.

server.set( 'storage', new RethinkDbConnector({
  port: 28015,
  host: rethinkDbHost,
  splitChar: '/',
  defaultTable: 'ds-records'
}));

There are no tables in the database at first. enter image description here

When I create a record, a table is created automatically if it does not exist.

var id = "chat/" + ds.getUid();
var record = ds.record.getRecord(id);

record.whenReady(function() {
  record.set({user: data.user, message: data.message, timestamp: Date.now(), id: id});
});

Table created as intended. enter image description here

However, if I try to create a "nested table", it does not work.

var id = "chat/idle_banter/" + ds.getUid();
var record = ds.record.getRecord(id);

record.whenReady(function() {
  record.set({user: data.user, message: data.message, timestamp: Date.now(), id: id});
});

No table is created when trying to create a record with the name 'table/collection/id' enter image description here

Do I have to create a table manually first, and then add the collection?


Edit

Clumsy use of terms on my part. I wish to create a table representing the entire chat, and then create a document that represents the actual room. New chat messages (records) would then be put in this document.


Solution

  • I have to admit that I don't think that RethinkDB supports a concept of nested tables. If you'd like to create a table per chat, just use a character other than the splitChar, e.g. 'chat-idle_banter/<recordName>'