GithubHelp home page GithubHelp logo

kristoiv / gocqltable Goto Github PK

View Code? Open in Web Editor NEW
52.0 52.0 16.0 342 KB

GoCqlTable is a wrapper around the GoCql-driver that seeks to simplify working with the Cassandra database in Golang projects.

License: Other

Go 100.00%

gocqltable's People

Contributors

annismckenzie avatar kristoiv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gocqltable's Issues

UnMarshalling of collection types is not supported?

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.