kristoiv / gocqltable Goto Github PK
View Code? Open in Web Editor NEWGoCqlTable is a wrapper around the GoCql-driver that seeks to simplify working with the Cassandra database in Golang projects.
License: Other
GoCqlTable is a wrapper around the GoCql-driver that seeks to simplify working with the Cassandra database in Golang projects.
License: Other
not work function Get and lists
UPDATE - looks like collections of UDT-s are not supported, as I was able to get it working with list or map<text, text> fields instead.
I have a schema defined like this (omitted some fields for simplicity):
CREATE TYPE IF NOT EXISTS firewire.address (
addressline text,
city text,
state text,
zipcode text
);
CREATE TABLE IF NOT EXISTS firewire.card_by_customer (
identitykey text,
firstname text static,
lastname text static,
createdate timestamp,
addresses map<text, frozen<address>> static,
accountid text,
// additional fields
. . .
PRIMARY KEY (identitykey, accountid)
) WITH CLUSTERING ORDER BY (accountid ASC);
And appropriate Golang structs defined as:
type CardByCustomer struct {
IdentityKey string 'cql:"identitykey"'
FirstName string 'cql:"firstname"'
LastName string 'cql:"lastname"'
CreateDate time.Time 'cql:"createdate"'
Addresses map[string]Address 'cql:"addresses"'
AccountID string 'cql:"accountid"'
// additional fields
. . .
}
type Address struct {
AddressLine string cql:"addressline"'
City string 'cql:"city"'
State string 'cql:"state"'
ZIPCode string 'cql:"zipcode"'
}
Code to initialize gocql and gocqltable:
// Generic initialization of gocql
cluster := gocql.NewCluster(hosts...)
cluster.Keyspace = keyspaceName
cluster.Consistency = gocql.Quorum
session, err := cluster.CreateSession()
if err != nil {
log.Fatalln("Unable to open up a session with the Cassandra database (err=" + err.Error() + ")")
}
defer session.Close()
// Tell gocqltable to use this session object as the default for new objects
gocqltable.SetDefaultSession(session)
// Set the current keyspace
keyspace = gocqltable.NewKeyspace(keyspaceName)`
Creating records into Cassandra works just fine:
newEntry := CardByCustomer{
IdentityKey: identityKey,
FirstName: "Isaak",
. . .
}
accountTable := EntityTable{
recipes.CRUD{ // EXAMPLE
keyspace.NewTable(
"card_by_customer", // The table name
[]string{"identitykey"}, // Row keys
nil, // Range keys
CardByCustomer{}, // We pass an instance of the CardByCustomer struct that will be used as a type template during fetches.
),
},
}
err := accountTable.Insert(newEntry)
if err != nil {
log.Fatalln(err)
}
But then I am trying retrieve single record or all records I am getting this:
Retrieving all records
panic: reflect.Set: value of type map[string]map[string]interface {} is not assignable to type map[string]main.Address
goroutine 85 [running]:
panic(0x22f440, 0xc42016d6b0)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
reflect.Value.assignTo(0xc420174cc0, 0xc42017ed20, 0x15, 0x283a59, 0xb, 0x240080, 0x0, 0xc42004fd78, 0xc420174cc0, 0xc42017ed20)
/usr/local/go/src/reflect/value.go:2163 +0x35c
reflect.Value.Set(0x240080, 0xc420184f00, 0x195, 0xc420174cc0, 0xc42017ed20, 0x15)
/usr/local/go/src/reflect/value.go:1333 +0xa4
github.com/kristoiv/gocqltable/reflect.MapToStruct(0xc42004fd78, 0x225040, 0xc420184ea0, 0x225040, 0xc420184ea0)
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/reflect/reflect.go:50 +0x31a
github.com/kristoiv/gocqltable.(*Iterator).Next(0xc42016f280, 0xc4200198d0, 0xdef75)
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/query.go:58 +0x160
github.com/kristoiv/gocqltable.(*Iterator).Range.func1(0xc42016f280, 0xc420174c00, 0xc420174c60)
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/query.go:69 +0x40
created by github.com/kristoiv/gocqltable.(*Iterator).Range
/Users/ggevorgyan/git/go/src/github.com/kristoiv/gocqltable/query.go:81 +0xac
I have tried to change my model using different approaches, but I need the built-in collection types, otherwise the model does not reflect what I need this for.
Thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.