refactor(schema)!: rename ObjectType -> StateObjectType (#21691)
Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
This commit is contained in:
co-authored by
cool-developer
parent
397ff0bd22
commit
ae40e809b9
@@ -79,11 +79,11 @@ func Example_objectIndexer_createTableSql_vote_no_retain_delete() {
|
||||
// GRANT SELECT ON TABLE "test_vote" TO PUBLIC;
|
||||
}
|
||||
|
||||
func exampleCreateTable(objectType schema.ObjectType) {
|
||||
func exampleCreateTable(objectType schema.StateObjectType) {
|
||||
exampleCreateTableOpt(objectType, false)
|
||||
}
|
||||
|
||||
func exampleCreateTableOpt(objectType schema.ObjectType, noRetainDelete bool) {
|
||||
func exampleCreateTableOpt(objectType schema.StateObjectType, noRetainDelete bool) {
|
||||
tm := newObjectIndexer("test", objectType, options{
|
||||
logger: logutil.NoopLogger{},
|
||||
disableRetainDeletions: noRetainDelete,
|
||||
|
||||
+4
-4
@@ -4,10 +4,10 @@ import "cosmossdk.io/schema"
|
||||
|
||||
var ExampleSchema schema.ModuleSchema
|
||||
|
||||
var AllKindsObject schema.ObjectType
|
||||
var AllKindsObject schema.StateObjectType
|
||||
|
||||
func init() {
|
||||
AllKindsObject = schema.ObjectType{
|
||||
AllKindsObject = schema.StateObjectType{
|
||||
Name: "all_kinds",
|
||||
KeyFields: []schema.Field{
|
||||
{
|
||||
@@ -45,7 +45,7 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
var SingletonObject = schema.ObjectType{
|
||||
var SingletonObject = schema.StateObjectType{
|
||||
Name: "singleton",
|
||||
ValueFields: []schema.Field{
|
||||
{
|
||||
@@ -65,7 +65,7 @@ var SingletonObject = schema.ObjectType{
|
||||
},
|
||||
}
|
||||
|
||||
var VoteObject = schema.ObjectType{
|
||||
var VoteObject = schema.StateObjectType{
|
||||
Name: "vote",
|
||||
KeyFields: []schema.Field{
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@ func (m *moduleIndexer) initializeSchema(ctx context.Context, conn dbConn) error
|
||||
}
|
||||
|
||||
// create tables for all object types
|
||||
m.schema.ObjectTypes(func(typ schema.ObjectType) bool {
|
||||
m.schema.StateObjectTypes(func(typ schema.StateObjectType) bool {
|
||||
tm := newObjectIndexer(m.moduleName, typ, m.options)
|
||||
m.tables[typ.Name] = tm
|
||||
err = tm.createTable(ctx, conn)
|
||||
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
// objectIndexer is a helper struct that generates SQL for a given object type.
|
||||
type objectIndexer struct {
|
||||
moduleName string
|
||||
typ schema.ObjectType
|
||||
typ schema.StateObjectType
|
||||
valueFields map[string]schema.Field
|
||||
allFields map[string]schema.Field
|
||||
options options
|
||||
}
|
||||
|
||||
// newObjectIndexer creates a new objectIndexer for the given object type.
|
||||
func newObjectIndexer(moduleName string, typ schema.ObjectType, options options) *objectIndexer {
|
||||
func newObjectIndexer(moduleName string, typ schema.StateObjectType, options options) *objectIndexer {
|
||||
allFields := make(map[string]schema.Field)
|
||||
valueFields := make(map[string]schema.Field)
|
||||
|
||||
|
||||
@@ -70,11 +70,11 @@ func (tm *objectIndexer) existsSqlAndParams(w io.Writer, key interface{}) ([]int
|
||||
return keyParams, err
|
||||
}
|
||||
|
||||
func (tm *objectIndexer) get(ctx context.Context, conn dbConn, key interface{}) (schema.ObjectUpdate, bool, error) {
|
||||
func (tm *objectIndexer) get(ctx context.Context, conn dbConn, key interface{}) (schema.StateObjectUpdate, bool, error) {
|
||||
buf := new(strings.Builder)
|
||||
params, err := tm.getSqlAndParams(buf, key)
|
||||
if err != nil {
|
||||
return schema.ObjectUpdate{}, false, err
|
||||
return schema.StateObjectUpdate{}, false, err
|
||||
}
|
||||
|
||||
sqlStr := buf.String()
|
||||
@@ -147,7 +147,7 @@ func (tm *objectIndexer) selectAllClause(w io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tm *objectIndexer) readRow(row interface{ Scan(...interface{}) error }) (schema.ObjectUpdate, bool, error) {
|
||||
func (tm *objectIndexer) readRow(row interface{ Scan(...interface{}) error }) (schema.StateObjectUpdate, bool, error) {
|
||||
var res []interface{}
|
||||
for _, f := range tm.typ.KeyFields {
|
||||
res = append(res, tm.colBindValue(f))
|
||||
@@ -164,16 +164,16 @@ func (tm *objectIndexer) readRow(row interface{ Scan(...interface{}) error }) (s
|
||||
err := row.Scan(res...)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return schema.ObjectUpdate{}, false, err
|
||||
return schema.StateObjectUpdate{}, false, err
|
||||
}
|
||||
return schema.ObjectUpdate{}, false, err
|
||||
return schema.StateObjectUpdate{}, false, err
|
||||
}
|
||||
|
||||
var keys []interface{}
|
||||
for _, field := range tm.typ.KeyFields {
|
||||
x, err := tm.readCol(field, res[0])
|
||||
if err != nil {
|
||||
return schema.ObjectUpdate{}, false, err
|
||||
return schema.StateObjectUpdate{}, false, err
|
||||
}
|
||||
keys = append(keys, x)
|
||||
res = res[1:]
|
||||
@@ -188,7 +188,7 @@ func (tm *objectIndexer) readRow(row interface{ Scan(...interface{}) error }) (s
|
||||
for _, field := range tm.typ.ValueFields {
|
||||
x, err := tm.readCol(field, res[0])
|
||||
if err != nil {
|
||||
return schema.ObjectUpdate{}, false, err
|
||||
return schema.StateObjectUpdate{}, false, err
|
||||
}
|
||||
values = append(values, x)
|
||||
res = res[1:]
|
||||
@@ -199,7 +199,7 @@ func (tm *objectIndexer) readRow(row interface{ Scan(...interface{}) error }) (s
|
||||
value = values[0]
|
||||
}
|
||||
|
||||
update := schema.ObjectUpdate{
|
||||
update := schema.StateObjectUpdate{
|
||||
TypeName: tm.typ.Name,
|
||||
Key: key,
|
||||
Value: value,
|
||||
|
||||
@@ -100,15 +100,15 @@ type objectView struct {
|
||||
conn dbConn
|
||||
}
|
||||
|
||||
func (tm *objectView) ObjectType() schema.ObjectType {
|
||||
func (tm *objectView) ObjectType() schema.StateObjectType {
|
||||
return tm.typ
|
||||
}
|
||||
|
||||
func (tm *objectView) GetObject(key interface{}) (update schema.ObjectUpdate, found bool, err error) {
|
||||
func (tm *objectView) GetObject(key interface{}) (update schema.StateObjectUpdate, found bool, err error) {
|
||||
return tm.get(tm.ctx, tm.conn, key)
|
||||
}
|
||||
|
||||
func (tm *objectView) AllState(f func(schema.ObjectUpdate, error) bool) {
|
||||
func (tm *objectView) AllState(f func(schema.StateObjectUpdate, error) bool) {
|
||||
buf := new(strings.Builder)
|
||||
err := tm.selectAllSql(buf)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user