Пример #1
0
func TestNewTableManager(t *testing.T) {
	assert.Equal(t, csdb.NewTableManager().Len(), csdb.Index(0))

	const (
		TableIndexStore   csdb.Index = iota // Table: store
		TableIndexGroup                     // Table: store_group
		TableIndexWebsite                   // Table: store_website
		TableIndexZZZ                       // the maximum index, which is not available.
	)

	tm1 := csdb.NewTableManager(
		csdb.AddTableByName(TableIndexStore, "store"),
		csdb.AddTableByName(TableIndexGroup, "store_group"),
		csdb.AddTableByName(TableIndexWebsite, "store_website"),
	)
	assert.Equal(t, tm1.Len(), csdb.Index(3))
}
Пример #2
0
func init() {
	TableCollection = csdb.NewTableManager(
		csdb.AddTableByName(TableIndexStore, "store"),
		csdb.AddTableByName(TableIndexGroup, "store_group"),
		csdb.AddTableByName(TableIndexWebsite, "store_website"),
	)
	// Don't forget to call TableCollection.ReInit(...) in your code to load the column definitions.
}
Пример #3
0
func TestNewTableManagerAppend(t *testing.T) {
	defer func() {
		if r := recover(); r != nil {
			assert.Contains(t, r.(string), "Table pointer cannot be nil for Index")
		}
	}()

	tm0 := csdb.NewTableManager()
	tm0.Append(csdb.Index(0), nil)
	assert.NotNil(t, tm0)
	assert.Equal(t, tm0.Len(), csdb.Index(0))
}
Пример #4
0
func TestNewTableManagerPanic(t *testing.T) {
	defer func() {
		if r := recover(); r != nil {
			assert.Contains(t, r.(string), csdb.ErrManagerIncorrectValue.Error())
		}
	}()

	tm0 := csdb.NewTableManager(
		csdb.AddTableByName(csdb.Index(0), ""),
	)
	assert.NotNil(t, tm0)
	assert.Equal(t, tm0.Len(), csdb.Index(0))
}
Пример #5
0
func TestNewTableManagerInit(t *testing.T) {
	dbc := csdb.MustConnectTest()
	defer dbc.Close()
	i := csdb.Index(4711)
	tm0 := csdb.NewTableManager(csdb.AddTableByName(i, "admin_user"))
	assert.EqualError(t, tm0.Init(dbc.NewSession(), true), csdb.ErrManagerInitReload.Error())
	err := tm0.Init(dbc.NewSession())
	assert.NoError(t, err)

	table, err2 := tm0.Structure(i)
	assert.NoError(t, err2)
	assert.Equal(t, 1, table.CountPK)
	assert.Equal(t, 1, table.CountUnique)
	assert.True(t, len(table.Columns.FieldNames()) >= 15)

	assert.Nil(t, tm0.Init(dbc.NewSession()))
}
Пример #6
0
func init() {
	tableMap = csdb.NewTableManager()
	tableMap.Append(
		table1,
		csdb.NewTable(
			"catalog_category_anc_categs_index_idx",
			csdb.Column{
				Field:   dbr.NewNullString("category_id"),
				Type:    dbr.NewNullString("int(10) unsigned"),
				Null:    dbr.NewNullString("NO"),
				Key:     dbr.NewNullString("MUL"),
				Default: dbr.NewNullString("0"),
				Extra:   dbr.NewNullString(""),
			},
			csdb.Column{
				Field:   dbr.NewNullString("path"),
				Type:    dbr.NewNullString("varchar(255)"),
				Null:    dbr.NewNullString("YES"),
				Key:     dbr.NewNullString("MUL"),
				Default: dbr.NullString{},
				Extra:   dbr.NewNullString(""),
			},
		),
	)
	tableMap.Append(
		table2,
		csdb.NewTable(
			"catalog_category_anc_categs_index_tmp",
			csdb.Column{
				Field:   dbr.NewNullString("category_id"),
				Type:    dbr.NewNullString("int(10) unsigned"),
				Null:    dbr.NewNullString("NO"),
				Key:     dbr.NewNullString("PRI"),
				Default: dbr.NewNullString("0"),
				Extra:   dbr.NewNullString(""),
			},
			csdb.Column{
				Field:   dbr.NewNullString("path"),
				Type:    dbr.NewNullString("varchar(255)"),
				Null:    dbr.NewNullString("YES"),
				Key:     dbr.NewNullString(nil),
				Default: dbr.NullString{},
				Extra:   dbr.NewNullString(""),
			},
		),
	)
	tableMap.Append(table3, csdb.NewTable(
		"catalog_category_anc_products_index_idx",
		csdb.Column{
			Field:   dbr.NewNullString("category_id"),
			Type:    dbr.NewNullString("int(10) unsigned"),
			Null:    dbr.NewNullString("NO"),
			Key:     dbr.NewNullString(nil),
			Default: dbr.NewNullString("0"),
			Extra:   dbr.NewNullString(""),
		},
		csdb.Column{
			Field:   dbr.NewNullString("product_id"),
			Type:    dbr.NewNullString("int(10) unsigned"),
			Null:    dbr.NewNullString("NO"),
			Key:     dbr.NewNullString(""),
			Default: dbr.NewNullString("0"),
			Extra:   dbr.NewNullString(""),
		},
		csdb.Column{
			Field:   dbr.NewNullString("position"),
			Type:    dbr.NewNullString("int(10) unsigned"),
			Null:    dbr.NewNullString("YES"),
			Key:     dbr.NewNullString(""),
			Default: dbr.NullString{},
			Extra:   dbr.NewNullString(""),
		},
	),
	)
	tableMap.Append(table4, csdb.NewTable(
		"admin_user",
		csdb.Column{
			Field:   dbr.NewNullString("user_id"),
			Type:    dbr.NewNullString("int(10) unsigned"),
			Null:    dbr.NewNullString("NO"),
			Key:     dbr.NewNullString("PRI"),
			Default: dbr.NullString{},
			Extra:   dbr.NewNullString("auto_increment"),
		},
		csdb.Column{
			Field:   dbr.NewNullString("email"),
			Type:    dbr.NewNullString("varchar(128)"),
			Null:    dbr.NewNullString("YES"),
			Key:     dbr.NewNullString(""),
			Default: dbr.NullString{},
			Extra:   dbr.NewNullString(""),
		},
		csdb.Column{
			Field:   dbr.NewNullString("username"),
			Type:    dbr.NewNullString("varchar(40)"),
			Null:    dbr.NewNullString("YES"),
			Key:     dbr.NewNullString("UNI"),
			Default: dbr.NullString{},
			Extra:   dbr.NewNullString(""),
		},
	),
	)
}
Пример #7
0
func init() {
	TableCollection = csdb.NewTableManager(
		csdb.AddTableByName(TableIndexCoreConfigData, "core_config_data"),
	)
	// Don't forget to call TableCollection.ReInit(...) in your code to load the column definitions.
}