Example #1
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.
}
Example #2
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))
}
Example #3
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))
}
Example #4
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()))
}
Example #5
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.
}