go - How to do INSERT IF NOT EXIST in gocql -
go - How to do INSERT IF NOT EXIST in gocql -
i've been reading http://godoc.org/github.com/gocql/gocql yet don't understand how insert -- if not exist gocql. stated
func (*query) scancas
func (q *query) scancas(dest ...interface{}) (applied bool, err error)
scancas executes lightweight transaction (i.e. update or insert statement containing if clause). if transaction fails because existing values did not match, previous values stored in dest.
when run
cluster := gocql.newcluster("127.0.0.1") cluster.keyspace = "example" cluster.consistency = gocql.quorum session, _ := cluster.createsession() defer session.close() var mapq map[string]interface{} var inserted bool var id gocql.uuid var timeline, text string // insert tweet istrue, err := session.query(`insert tweet (timeline, id, text) values (?, ?, ?) if not exist`, "hermano", gocql.timeuuid(), "good night"). scancas(); if err != nil { log.println(err) } fmt.println(timeline, id, text) fmt.printf("%+v\n", istrue) fmt.printf("%+v\n", inserted) fmt.printf("%+v\n", mapq)
i get: failed parsing statement: [insert tweet (timeline, id, text) values (?, ?, ?) if not exist] reason: arrayindexoutofboundsexception -1
so question is: 1. how insert if not exist in gocql? can guys give me example? 2. how proper scancas? 3. makes mapscancas , scancas different? don't understand what column mismatching author talking about 4. there page explains gocql beside godoc page?
looks typo, should utilize "if not exists"
go cassandra gocql
Comments
Post a Comment