loopbackio / loopback-connector-cassandra

Cassandra connector for the LoopBack framework.
Other
13 stars 22 forks source link

Support Collections #59

Closed shenghu closed 6 years ago

shenghu commented 6 years ago

Description

We need use Cassandra collections. Current cassandra connector doesn't support to define table using collections, as well as inserting/updating column of collection type. This PR adds capabilities to

  1. Define model property to be collection type In general, cassandra.dataType is required for cassandra connector to understand what type of cassandra dataType should be used. If cassandra.dataType is not set, cassandra connector will infer cassandra dataType from loopback data type, e.g. String is mapped to TEXT, Array/Object is mapped to TEXT. E.g. data: [String] is a TEXT in cassandra db, while data: { type: [String], cassandra: {dataType: 'Set<Text>'}} is a Set in cassandra. The reason that Array/Object is not mapped to collection when cassandra.dataType is not set is because cassandra connector extends SqlConnector which convert Array/Object to string. A lot of tests from loopback-datasource-juggler/test/common.batch.js and loopback-datasource-juggler/test/include.test.js will fail if we change this behavior.

Note that: nested collections is not fully supported in this PR. It can be used to define model. But there is error to insert/update it. For now, I don't think nested collection is used frequently. So it can be deferred.

  1. Insert/update collection type of data Note that the column data is updated as a whole. Special operations of collections will be added later.

Related issues

Checklist

shenghu commented 6 years ago

@Setogit @kjdelisle @jannyHou @dhmlau can you please review this PR?

dhmlau commented 6 years ago

@raymondfeng @jannyHou , could you please review?

jannyHou commented 6 years ago

Hi @shenghu I may not have the bandwidth to review it immediately, while will try to finish by the end of this week.

shenghu commented 6 years ago

@jannyHou @raymondfeng any chance you can review this pr? :)

shenghu commented 6 years ago

Due to https://travis-ci.org/strongloop/loopback-connector-cassandra/jobs/394239529, I remove running test for nodes 4. The dependency now requires strong-globalize@4.1.0 which requires nodes > 6. (Note that this is not introduced by this PR. )

And I think now there is no need to support nodejs 4.

shenghu commented 6 years ago

@jannyHou @dhmlau any update or progress?

jannyHou commented 6 years ago

@shenghu reviewing it :) may take a few hours.

jannyHou commented 6 years ago

@shenghu BTW, please squash 5 commits to 1 :) thanks.

shenghu commented 6 years ago

@jannyHou added nodes 8 and 10 to travis and both passed.

jannyHou commented 6 years ago

@shenghu Cheers 🎉 Another great feature merged. Thank you!

shenghu commented 6 years ago

@dhmlau I don't see version bumped automatically. Is there anything I missed?

dhmlau commented 6 years ago

I just released it.