Navigation Menu

Skip to content

Commit

Permalink
Gnx: implement LoadCMap().
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yata committed Apr 1, 2015
1 parent b44dec4 commit 722d0f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
11 changes: 9 additions & 2 deletions go2/gnx/gnx.go
Expand Up @@ -837,8 +837,15 @@ func (db *DB) loadC(

func (db *DB) loadCMap(
tableName string, columnarRecordsMap map[string]interface{}) (int, error) {
// TODO
return 0, nil
columnNames := make([]string, len(columnarRecordsMap))
columnarRecords := make([]interface{}, len(columnarRecordsMap))
i := 0
for columnName, columnarValues := range columnarRecordsMap {
columnNames[i] = columnName
columnarRecords[i] = columnarValues
i++
}
return db.loadC(tableName, columnNames, columnarRecords)
}

func (db *DB) Load(
Expand Down
35 changes: 24 additions & 11 deletions go2/gnxTest.go
Expand Up @@ -194,7 +194,7 @@ func testB() {
var columnarRecords []interface{}
// NOTE: In fact, the IDs are ignored.
columnarRecords = append(columnarRecords, []gnx.Int{5,6,7,8})
columnarRecords = append(columnarRecords, []gnx.Int{-10,-20,-30,-40})
columnarRecords = append(columnarRecords, []gnx.Int{-5,-6,-7,-8})
count, err := db.LoadC("Table", []string{"_id", "Value"}, columnarRecords)
if err != nil {
log.Println(err)
Expand All @@ -203,16 +203,29 @@ func testB() {
fmt.Println("count:", count)
}

// {
// columnarRecordsMap := make(map[string]interface{})
// columnarRecordsMap["Value"] = []gnx.Int{-100,-200,-300}
// count, err := db.LoadCMap("Table", columnarRecordsMap)
// if err != nil {
// log.Println(err)
// return
// }
// fmt.Println("count:", count)
// }
{
columnarRecordsMap := make(map[string]interface{})
columnarRecordsMap["Value"] = []gnx.Int{-10,-20,-30,-40}
count, err := db.LoadCMap("Table", columnarRecordsMap)
if err != nil {
log.Println(err)
return
}
fmt.Println("count:", count)
}

{
columnarRecordsMap := make(map[string]interface{})
// NOTE: In fact, the IDs are ignored.
columnarRecordsMap["_id"] = []gnx.Int{9,10,11,12}
columnarRecordsMap["Value"] = []gnx.Int{-50,-60,-70,-80}
count, err := db.LoadCMap("Table", columnarRecordsMap)
if err != nil {
log.Println(err)
return
}
fmt.Println("count:", count)
}

command := "select Table --limit -1"
for i := 0; i < 3; i++ {
Expand Down

0 comments on commit 722d0f7

Please sign in to comment.