susumu.yata
null+****@clear*****
Tue Jun 23 22:42:05 JST 2015
susumu.yata 2015-06-23 22:42:05 +0900 (Tue, 23 Jun 2015) New Revision: 0df94294c15c0dd53096d03c4f4c173f8bf1f199 https://github.com/groonga/grngo/commit/0df94294c15c0dd53096d03c4f4c173f8bf1f199 Message: Update TableOptions and tests. Replace TableType and WithSIS with Flags. Rename constants. ArrayTable -> TableNoKey PatTable -> TablePatKey DatTable -> TableDatKey HashTable -> TableHashKey Add a constant KeyWithSIS. GitHub: #7 Modified files: grngo.go grngo_test.go Modified: grngo.go (+14 -16) =================================================================== --- grngo.go 2015-06-23 17:32:19 +0900 (f60d88b) +++ grngo.go 2015-06-23 22:42:05 +0900 (2ba3f3a) @@ -94,20 +94,18 @@ func (dataType DataType) String() string { // -- TableOptions -- -// Constants for TableOptions. -type TableType int - const ( - ArrayTable = TableType(iota) - HashTable - PatTable - DatTable + TableTypeMask = C.GRN_OBJ_TABLE_TYPE_MASK + TableNoKey = C.GRN_OBJ_TABLE_NO_KEY + TablePatKey = C.GRN_OBJ_TABLE_PAT_KEY + TableDatKey = C.GRN_OBJ_TABLE_DAT_KEY + TableHashKey = C.GRN_OBJ_TABLE_HASH_KEY + KeyWithSIS = C.GRN_OBJ_KEY_WITH_SIS ) // http://groonga.org/docs/reference/commands/table_create.html type TableOptions struct { - TableType - WithSIS bool // KEY_WITH_SIS + Flags int KeyType string // http://groonga.org/docs/reference/types.html ValueType string // http://groonga.org/docs/reference/types.html DefaultTokenizer string // http://groonga.org/docs/reference/tokenizers.html @@ -119,7 +117,7 @@ type TableOptions struct { // settings. func NewTableOptions() *TableOptions { var options TableOptions - options.TableType = HashTable + options.Flags = TableHashKey return &options } @@ -376,20 +374,20 @@ func (db *DB) CreateTable(name string, options *TableOptions) (*Table, error) { if options.KeyType == "" { optionsMap["flags"] = "TABLE_NO_KEY" } else { - switch options.TableType { - case ArrayTable: + switch options.Flags & TableTypeMask { + case TableNoKey: optionsMap["flags"] = "TABLE_NO_KEY" - case HashTable: + case TableHashKey: optionsMap["flags"] = "TABLE_HASH_KEY" - case PatTable: + case TablePatKey: optionsMap["flags"] = "TABLE_PAT_KEY" - case DatTable: + case TableDatKey: optionsMap["flags"] = "TABLE_DAT_KEY" default: return nil, fmt.Errorf("undefined table type: options = %+v", options) } } - if options.WithSIS { + if (options.Flags & KeyWithSIS) == KeyWithSIS { optionsMap["flags"] += "|KEY_WITH_SIS" } if options.KeyType != "" { Modified: grngo_test.go (+0 -10) =================================================================== --- grngo_test.go 2015-06-23 17:32:19 +0900 (0467e30) +++ grngo_test.go 2015-06-23 22:42:05 +0900 (976d03b) @@ -84,7 +84,6 @@ func TestOpenDB(t *testing.T) { func testDBCreateTableWithKey(t *testing.T, keyType string) { options := NewTableOptions() - options.TableType = PatTable options.KeyType = keyType dirPath, _, db, _ := createTempTable(t, "Table", options) removeTempDB(t, dirPath, db) @@ -92,7 +91,6 @@ func testDBCreateTableWithKey(t *testing.T, keyType string) { func testDBCreateTableWithValue(t *testing.T, valueType string) { options := NewTableOptions() - options.TableType = PatTable options.ValueType = valueType dirPath, _, db, _ := createTempTable(t, "Table", options) removeTempDB(t, dirPath, db) @@ -100,13 +98,11 @@ func testDBCreateTableWithValue(t *testing.T, valueType string) { func testDBCreateTableWithRefKey(t *testing.T, keyType string) { options := NewTableOptions() - options.TableType = PatTable options.KeyType = keyType dirPath, _, db, _ := createTempTable(t, "To", options) defer removeTempDB(t, dirPath, db) options = NewTableOptions() - options.TableType = PatTable options.KeyType = "To" _, err := db.CreateTable("From", options) if err != nil { @@ -116,7 +112,6 @@ func testDBCreateTableWithRefKey(t *testing.T, keyType string) { func testDBCreateTableWithRefValue(t *testing.T, keyType string) { options := NewTableOptions() - options.TableType = PatTable options.KeyType = keyType dirPath, _, db, _ := createTempTable(t, "To", options) defer removeTempDB(t, dirPath, db) @@ -285,9 +280,6 @@ func generateRandomKey(keyType string) interface{} { func testTableInsertRow(t *testing.T, keyType string) { options := NewTableOptions() - if keyType != "" { - options.TableType = PatTable - } options.KeyType = keyType dirPath, _, db, table := createTempTable(t, "Table", options) defer removeTempDB(t, dirPath, db) @@ -401,7 +393,6 @@ func testTableCreateVectorColumn(t *testing.T, valueType string) { func testTableCreateScalarRefColumn(t *testing.T, keyType string) { options := NewTableOptions() - options.TableType = PatTable options.KeyType = keyType dirPath, _, db, table, _ := createTempColumn(t, "Table", options, "Value", "Table", nil) @@ -426,7 +417,6 @@ func testTableCreateScalarRefColumn(t *testing.T, keyType string) { func testTableCreateVectorRefColumn(t *testing.T, keyType string) { tableOptions := NewTableOptions() - tableOptions.TableType = PatTable tableOptions.KeyType = keyType dirPath, _, db, table, _ := createTempColumn(t, "Table", tableOptions, "Value", "[]Table", nil) -------------- next part -------------- HTML����������������������������... Descargar