Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batches #11

Open
szavrakas opened this issue Jan 10, 2017 · 3 comments
Open

Batches #11

szavrakas opened this issue Jan 10, 2017 · 3 comments

Comments

@szavrakas
Copy link

Hi guys,

We are looking at datastar and the concepts and the abstractions seems really nice. We have some questions about the batches. Here is the scenario:

We have a rest api and we have users and the threads resources. When we are posting a user we have to create a thread as well. The two tables that we currently have are:

users with fields (user_id, first_name, last_name, password)
threads with fields (thread_id, subject, user_id)

We are going to define the schema like that:

const cql = datastar.schema.cql;

const users = datastar.define('users', {
  ensureTables: true,
  schema: datastar.schema.object({
    user_id: cql.timeuuid({ default: 'v4' }),
    first_name: cql.text(),
    last_name: cql.text(),
    password: cql.text()
  }).partitionKey('user_id')
});

const threads = datastar.define('threads', {
  ensureTables: true,
  schema: datastar.schema.object({
    thread_id: cql.timeuuid({ default: 'v4' }),
    subject: cql.text().allow(null),
    user_id: cql.timeuuid()
  }).partitionKey('thread_id')
    .lookupKeys('user_id')
});

The fact that we've defined the threads schema above with the user_id as lookupKey it will create under the hood the table threads_by_user_id and when we are acting against the threads model/schema datastar will update the values in both tables using batches. Is this the case?

The question is how can we insert/update in batch between different model/schemas? For example, we would like to insert in the users table and the threads table (and sub-tables) and we would like to do it in a batch. Finally to insert to the following tables

users
threads
threads_by_user_id

As we see here on the blogpost one of the next features will be the batch update on multiple models. Is it the same thing that we are asking for and can we help somehow on that one?

Another thing that we'd like to ask is about the types. There are quite a lot of types defined, but we are using smallint as well. Is it enough to do the change on the joi-of-cql project or do we need to adapt this project accordingly?

Many thanks and sorry for the long post!

@jcrugzz
Copy link
Collaborator

jcrugzz commented Feb 28, 2017

@szavrakas apologies for the late and brief answer. The best example I have for how to batch multiple models is how I use it here. Check line 395 for usage of this method. The idea is that you build an array of functions to be executed by async.waterfall which handles the batch combining machinery (since the api is async). You then get a returned statements object to your last function which you then execute. Final bits can be seen here

@szavrakas
Copy link
Author

@jcrugzz thanks for the response. I don't have access to the examples that you've provided. Can you just create a small example here?

@jcrugzz
Copy link
Collaborator

jcrugzz commented Mar 1, 2017

@szavrakas sorry, fixed it for you. links are updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants