How Mapper handles updates/delete to/from set/list/map

156 views
Skip to first unread message

Yarden Bar

unread,
May 24, 2020, 1:30:54 AM5/24/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hello,

I have a table with complex types (not UDTs), such as:
field1 text,
field2 text,
field3 set<text>,
PRIMARY KEY (field1)


Reading the documentation, I could not deduce how the Mapper will handle updates/upserts/deletes to/from set/list/map.

My guess would be that if its not supported, then I'd need to use "mapWithQuery" to bypass the query generation.

Any direction will help,
J

Jorge Bay Gondra

unread,
May 25, 2020, 4:12:02 AM5/25/20
to nodejs-dr...@lists.datastax.com
Hi,
The Mapper uses the default type mapping of the core driver, you can look at the documentation for CQL types to ECMAScript types here: https://docs.datastax.com/en/developer/nodejs-driver/4.5/features/datatypes/

For example, given the schema you send, it would be something like:

sampleMapper.insert({ field1: 'value a', field2: 'value b', field3: [ 'set value 1', 'set value 2' ] })

Thanks,
Jorge

--
You received this message because you are subscribed to the Google Groups "DataStax Node.js Driver for Apache Cassandra Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.
To view this discussion on the web visit https://groups.google.com/a/lists.datastax.com/d/msgid/nodejs-driver-user/f78c600c-ece5-4bea-931a-606458f7ffa1%40lists.datastax.com.


--
Jorge Bay Gondra

Yarden Bar

unread,
Jun 17, 2020, 3:28:11 PM6/17/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Hi Jorge,
Thank you for the example. how would that work for updates?
Wholesale approach where i have to read the collection first, modify it and update the new value?
or
Updating a collection has some syntax similar to CQL "mySet = mySet - itemsToRemove"?

Thank you,
Yarden

On Monday, May 25, 2020 at 1:12:02 AM UTC-7, Jorge Bay Gondra wrote:
Hi,
The Mapper uses the default type mapping of the core driver, you can look at the documentation for CQL types to ECMAScript types here: https://docs.datastax.com/en/developer/nodejs-driver/4.5/features/datatypes/

For example, given the schema you send, it would be something like:

sampleMapper.insert({ field1: 'value a', field2: 'value b', field3: [ 'set value 1', 'set value 2' ] })

Thanks,
Jorge

On Sun, May 24, 2020 at 7:30 AM Yarden Bar <ayash...@gmail.com> wrote:
Hello,

I have a table with complex types (not UDTs), such as:
field1 text,
field2 text,
field3 set<text>,
PRIMARY KEY (field1)


Reading the documentation, I could not deduce how the Mapper will handle updates/upserts/deletes to/from set/list/map.

My guess would be that if its not supported, then I'd need to use "mapWithQuery" to bypass the query generation.

Any direction will help,
J

--
You received this message because you are subscribed to the Google Groups "DataStax Node.js Driver for Apache Cassandra Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.


--
Jorge Bay Gondra

Jorge Bay Gondra

unread,
Jun 18, 2020, 5:05:24 AM6/18/20
to nodejs-dr...@lists.datastax.com
Hi,
The update statements would work in the same way for a full value replacement.

If you want to add values to the set (if not already there), you can use q.append():

// import q
const q = cassandra.mapping.q;

// Use q.append() in a update query for the column "tags"
videoMapper.update({ id, tags: q.append(['coding', 'nodejs']) })


Thanks,
Jorge


To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.


--
Jorge Bay Gondra

--
You received this message because you are subscribed to the Google Groups "DataStax Node.js Driver for Apache Cassandra Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.
To view this discussion on the web visit https://groups.google.com/a/lists.datastax.com/d/msgid/nodejs-driver-user/72e7daa3-6c14-4089-a266-b81f8742f38fo%40lists.datastax.com.


--
Jorge Bay Gondra

Yarden Bar

unread,
Jun 19, 2020, 12:34:04 PM6/19/20
to DataStax Node.js Driver for Apache Cassandra Mailing List
Great! I'll look into that


On Thursday, June 18, 2020 at 2:05:24 AM UTC-7, Jorge Bay Gondra wrote:
Hi,
The update statements would work in the same way for a full value replacement.

If you want to add values to the set (if not already there), you can use q.append():

// import q
const q = cassandra.mapping.q;

// Use q.append() in a update query for the column "tags"
videoMapper.update({ id, tags: q.append(['coding', 'nodejs']) })


Thanks,
Jorge

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.


--
Jorge Bay Gondra

--
You received this message because you are subscribed to the Google Groups "DataStax Node.js Driver for Apache Cassandra Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-user+unsub...@lists.datastax.com.


--
Jorge Bay Gondra

Reply all
Reply to author
Forward
0 new messages