- 授权协议: BSD
- 开发语言: Google Go
- 操作系统: 跨平台
- 软件首页: https://github.com/elvtechnology/gocqltable
- 软件文档: https://godoc.org/github.com/elvtechnology/gocqltable
软件介绍
GoCqlTable 封装了 GoCql-driver 目的是简化 Go 语言操作 Cassandra 数据库。
示例代码:
// Generic initialization of gocql c := gocql.NewCluster("127.0.0.1") s, err := c.CreateSession() if err != nil { log.Fatalln("Unable to open up a session with the Cassandra database (err=" + err.Error() + ")") } // Tell gocqltable to use this session object as the default for new objects gocqltable.SetDefaultSession(s) // Now we're ready to create our first keyspace. We start by getting a keyspace object keyspace := gocqltable.NewKeyspace("gocqltable_test") // Now lets create that in the database using the simple strategy and durable writes (true) err = keyspace.Create(map[string]interface{}{ "class": "SimpleStrategy", "replication_factor": 1, }, true) if err != nil { // If something went wrong we print the error and quit. log.Fatalln(err) } // Now that we have a very own keyspace to play with, lets create our first table. // First we need a Row-object to base the table on. It will later be passed to the table wrapper // to be used for returning row-objects as the answer to fetch requests. type User struct{ Email string // Our primary key Password string `password` // Use Tags to rename fields Active bool `cql:"active"` // If there are multiple tags, use `cql:""` to specify what the table column will be Created time.Time } // Let's define and instantiate a table object for our user table userTable := struct{ recipes.CRUD // If you looked at the base example first, notice we replaced this line with the recipe }{ recipes.CRUD{ // Here we didn't replace, but rather wrapped the table object in our recipe, effectively adding more methods to the end API keyspace.NewTable( "users", // The table name []string{"email"}, // Row keys nil, // Range keys User{}, // We pass an instance of the user struct that will be used as a type template during fetches. ), }, } // Lets create this table in our cassandra database err = userTable.Create() if err != nil { log.Fatalln(err) } // Now that we have a keyspace with a table in it: lets make a few rows! In the base example we had to write out the CQL manually, this time // around, however, we can insert entire User objects. // Lets instantiate a user object, set its values and insert it user1 := User{ Email: "1@example.com", Password: "123456", Active: true, Created: time.Now().UTC(), } err = userTable.Insert(user1) if err != nil { log.Fatalln(err) } // With our database filled up with users, lets query it and print out the results (containing all users in the database). rowset, err := userTable.List() for _, row := range rowset { user := row.(*User) // Our row variable is a pointer to "interface{}", and here we type assert it to a pointer to "User" } if err != nil { log.Fatalln(err) } // You can also fetch a single row, obviously row, err := userTable.Get("1@example.com") if err != nil { log.Fatalln(err) } user := row.(*User) // Lets update this user by changing his password user.Password = "654321" err = userTable.Update(user) if err != nil { log.Fatalln(err) } // Lets delete user 1@example.com err = userTable.Delete(user) if err != nil { log.Fatalln(err) } // Lets clean up after ourselves by dropping the keyspace. keyspace.Drop()
数据结构与算法经典问题解析
纳拉辛哈·卡鲁曼希 / 骆嘉伟 / 机械工业出版社 / 2016-6-1 / CNY 79.00
本书是一本数据结构方面的优秀教材,以Java为描述语言,介绍了计算机编程中使用的数据结构和算法。本书强调问题及其分析,而非理论阐述,共分为21章,讲述了基本概念、递归和回溯、链表、栈、队列、树、优先队列和堆、并查集DAT、图算法、排序、查找、选择算法(中位数)、符号表、散列、字符串算法、算法设计技术、贪婪算法、分治算法、动态规划算法、复杂度类型等内容。每章首先阐述必要的理论基础,然后给出问题集。全......一起来看看 《数据结构与算法经典问题解析》 这本书的介绍吧!