c# - How to update List<string> column using Mapper.UpdateAsync in Cassandra? -
i newbie cassandra , current project called me create table following columns:
id uuid primary key, connections list<text>, username text
i using cassandra's imapper interface handle crud operations. while found documentation describes how use mapping component basic operations here:
http://docs.datastax.com/en/developer/csharp-driver/2.5/csharp-driver/reference/mappercomponent.html
i not find documentation outlines how add , remove items list column specific record using mapper component. tried retrieve record database, update entity , save changes record record not updated in database. remains same after update. however, insert operation works , mirrors entity down object in list.
user user = await _mapper.singleasync<t>("where name = " + name); user.addresses = user.addresses.concat(new string[] { address }); await _mapper.updateasync<t>(user);
how should scenario handled in cassandra?
you can use plus (+) , minus (-) cql operators append / prepend or remove items list.
in case be:
// when using parameters, use query markers (?) instead of // hardcoded stringified values user user = await _mapper.singleasync<user>("where id = ?", id); await _mapper.updateasync<t>( "set connections = connections + ? id = ?", newconnections, id");
note append , prepend operations not idempotent nature. in particular, if 1 of these operation timeout, retrying operation not safe , may (or may not) lead appending/prepending value twice.
Comments
Post a Comment