github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/chain_height__generated.go (about)

     1  // This is a generated source file. DO NOT EDIT
     2  // Source: models/chain_height__generated.go
     3  
     4  package models
     5  
     6  import (
     7  	"fmt"
     8  	"time"
     9  
    10  	"github.com/machinefi/w3bstream/pkg/depends/base/types"
    11  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx"
    12  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder"
    13  )
    14  
    15  var ChainHeightTable *builder.Table
    16  
    17  func init() {
    18  	ChainHeightTable = MonitorDB.Register(&ChainHeight{})
    19  }
    20  
    21  type ChainHeightIterator struct {
    22  }
    23  
    24  func (*ChainHeightIterator) New() interface{} {
    25  	return &ChainHeight{}
    26  }
    27  
    28  func (*ChainHeightIterator) Resolve(v interface{}) *ChainHeight {
    29  	return v.(*ChainHeight)
    30  }
    31  
    32  func (*ChainHeight) TableName() string {
    33  	return "t_chain_height"
    34  }
    35  
    36  func (*ChainHeight) TableDesc() []string {
    37  	return []string{
    38  		"ChainHeight database model chainheight",
    39  	}
    40  }
    41  
    42  func (*ChainHeight) Comments() map[string]string {
    43  	return map[string]string{}
    44  }
    45  
    46  func (*ChainHeight) ColDesc() map[string][]string {
    47  	return map[string][]string{}
    48  }
    49  
    50  func (*ChainHeight) ColRel() map[string][]string {
    51  	return map[string][]string{}
    52  }
    53  
    54  func (*ChainHeight) PrimaryKey() []string {
    55  	return []string{
    56  		"ID",
    57  	}
    58  }
    59  
    60  func (m *ChainHeight) IndexFieldNames() []string {
    61  	return []string{
    62  		"ChainHeightID",
    63  		"ChainID",
    64  		"ChainName",
    65  		"EventType",
    66  		"Height",
    67  		"ID",
    68  		"ProjectName",
    69  		"Uniq",
    70  	}
    71  }
    72  
    73  func (*ChainHeight) UniqueIndexes() builder.Indexes {
    74  	return builder.Indexes{
    75  		"ui_chain_height_id": []string{
    76  			"ChainHeightID",
    77  		},
    78  		"ui_chain_height_uniq": []string{
    79  			"ProjectName",
    80  			"EventType",
    81  			"ChainID",
    82  			"ChainName",
    83  			"Height",
    84  			"Uniq",
    85  		},
    86  	}
    87  }
    88  
    89  func (*ChainHeight) UniqueIndexUIChainHeightID() string {
    90  	return "ui_chain_height_id"
    91  }
    92  
    93  func (*ChainHeight) UniqueIndexUIChainHeightUniq() string {
    94  	return "ui_chain_height_uniq"
    95  }
    96  
    97  func (m *ChainHeight) ColID() *builder.Column {
    98  	return ChainHeightTable.ColByFieldName(m.FieldID())
    99  }
   100  
   101  func (*ChainHeight) FieldID() string {
   102  	return "ID"
   103  }
   104  
   105  func (m *ChainHeight) ColChainHeightID() *builder.Column {
   106  	return ChainHeightTable.ColByFieldName(m.FieldChainHeightID())
   107  }
   108  
   109  func (*ChainHeight) FieldChainHeightID() string {
   110  	return "ChainHeightID"
   111  }
   112  
   113  func (m *ChainHeight) ColProjectName() *builder.Column {
   114  	return ChainHeightTable.ColByFieldName(m.FieldProjectName())
   115  }
   116  
   117  func (*ChainHeight) FieldProjectName() string {
   118  	return "ProjectName"
   119  }
   120  
   121  func (m *ChainHeight) ColFinished() *builder.Column {
   122  	return ChainHeightTable.ColByFieldName(m.FieldFinished())
   123  }
   124  
   125  func (*ChainHeight) FieldFinished() string {
   126  	return "Finished"
   127  }
   128  
   129  func (m *ChainHeight) ColUniq() *builder.Column {
   130  	return ChainHeightTable.ColByFieldName(m.FieldUniq())
   131  }
   132  
   133  func (*ChainHeight) FieldUniq() string {
   134  	return "Uniq"
   135  }
   136  
   137  func (m *ChainHeight) ColEventType() *builder.Column {
   138  	return ChainHeightTable.ColByFieldName(m.FieldEventType())
   139  }
   140  
   141  func (*ChainHeight) FieldEventType() string {
   142  	return "EventType"
   143  }
   144  
   145  func (m *ChainHeight) ColChainID() *builder.Column {
   146  	return ChainHeightTable.ColByFieldName(m.FieldChainID())
   147  }
   148  
   149  func (*ChainHeight) FieldChainID() string {
   150  	return "ChainID"
   151  }
   152  
   153  func (m *ChainHeight) ColChainName() *builder.Column {
   154  	return ChainHeightTable.ColByFieldName(m.FieldChainName())
   155  }
   156  
   157  func (*ChainHeight) FieldChainName() string {
   158  	return "ChainName"
   159  }
   160  
   161  func (m *ChainHeight) ColHeight() *builder.Column {
   162  	return ChainHeightTable.ColByFieldName(m.FieldHeight())
   163  }
   164  
   165  func (*ChainHeight) FieldHeight() string {
   166  	return "Height"
   167  }
   168  
   169  func (m *ChainHeight) ColPaused() *builder.Column {
   170  	return ChainHeightTable.ColByFieldName(m.FieldPaused())
   171  }
   172  
   173  func (*ChainHeight) FieldPaused() string {
   174  	return "Paused"
   175  }
   176  
   177  func (m *ChainHeight) ColCreatedAt() *builder.Column {
   178  	return ChainHeightTable.ColByFieldName(m.FieldCreatedAt())
   179  }
   180  
   181  func (*ChainHeight) FieldCreatedAt() string {
   182  	return "CreatedAt"
   183  }
   184  
   185  func (m *ChainHeight) ColUpdatedAt() *builder.Column {
   186  	return ChainHeightTable.ColByFieldName(m.FieldUpdatedAt())
   187  }
   188  
   189  func (*ChainHeight) FieldUpdatedAt() string {
   190  	return "UpdatedAt"
   191  }
   192  
   193  func (m *ChainHeight) CondByValue(db sqlx.DBExecutor) builder.SqlCondition {
   194  	var (
   195  		tbl  = db.T(m)
   196  		fvs  = builder.FieldValueFromStructByNoneZero(m)
   197  		cond = make([]builder.SqlCondition, 0)
   198  	)
   199  
   200  	for _, fn := range m.IndexFieldNames() {
   201  		if v, ok := fvs[fn]; ok {
   202  			cond = append(cond, tbl.ColByFieldName(fn).Eq(v))
   203  			delete(fvs, fn)
   204  		}
   205  	}
   206  	if len(cond) == 0 {
   207  		panic(fmt.Errorf("no field for indexes has value"))
   208  	}
   209  	for fn, v := range fvs {
   210  		cond = append(cond, tbl.ColByFieldName(fn).Eq(v))
   211  	}
   212  	return builder.And(cond...)
   213  }
   214  
   215  func (m *ChainHeight) Create(db sqlx.DBExecutor) error {
   216  
   217  	if m.CreatedAt.IsZero() {
   218  		m.CreatedAt.Set(time.Now())
   219  	}
   220  
   221  	if m.UpdatedAt.IsZero() {
   222  		m.UpdatedAt.Set(time.Now())
   223  	}
   224  
   225  	_, err := db.Exec(sqlx.InsertToDB(db, m, nil))
   226  	return err
   227  }
   228  
   229  func (m *ChainHeight) List(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) ([]ChainHeight, error) {
   230  	var (
   231  		tbl = db.T(m)
   232  		lst = make([]ChainHeight, 0)
   233  	)
   234  	adds = append([]builder.Addition{builder.Where(cond), builder.Comment("ChainHeight.List")}, adds...)
   235  	err := db.QueryAndScan(builder.Select(nil).From(tbl, adds...), &lst)
   236  	return lst, err
   237  }
   238  
   239  func (m *ChainHeight) Count(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) (cnt int64, err error) {
   240  	tbl := db.T(m)
   241  	adds = append([]builder.Addition{builder.Where(cond), builder.Comment("ChainHeight.List")}, adds...)
   242  	err = db.QueryAndScan(builder.Select(builder.Count()).From(tbl, adds...), &cnt)
   243  	return
   244  }
   245  
   246  func (m *ChainHeight) FetchByID(db sqlx.DBExecutor) error {
   247  	tbl := db.T(m)
   248  	err := db.QueryAndScan(
   249  		builder.Select(nil).
   250  			From(
   251  				tbl,
   252  				builder.Where(
   253  					builder.And(
   254  						tbl.ColByFieldName("ID").Eq(m.ID),
   255  					),
   256  				),
   257  				builder.Comment("ChainHeight.FetchByID"),
   258  			),
   259  		m,
   260  	)
   261  	return err
   262  }
   263  
   264  func (m *ChainHeight) FetchByChainHeightID(db sqlx.DBExecutor) error {
   265  	tbl := db.T(m)
   266  	err := db.QueryAndScan(
   267  		builder.Select(nil).
   268  			From(
   269  				tbl,
   270  				builder.Where(
   271  					builder.And(
   272  						tbl.ColByFieldName("ChainHeightID").Eq(m.ChainHeightID),
   273  					),
   274  				),
   275  				builder.Comment("ChainHeight.FetchByChainHeightID"),
   276  			),
   277  		m,
   278  	)
   279  	return err
   280  }
   281  
   282  func (m *ChainHeight) FetchByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniq(db sqlx.DBExecutor) error {
   283  	tbl := db.T(m)
   284  	err := db.QueryAndScan(
   285  		builder.Select(nil).
   286  			From(
   287  				tbl,
   288  				builder.Where(
   289  					builder.And(
   290  						tbl.ColByFieldName("ProjectName").Eq(m.ProjectName),
   291  						tbl.ColByFieldName("EventType").Eq(m.EventType),
   292  						tbl.ColByFieldName("ChainID").Eq(m.ChainID),
   293  						tbl.ColByFieldName("ChainName").Eq(m.ChainName),
   294  						tbl.ColByFieldName("Height").Eq(m.Height),
   295  						tbl.ColByFieldName("Uniq").Eq(m.Uniq),
   296  					),
   297  				),
   298  				builder.Comment("ChainHeight.FetchByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniq"),
   299  			),
   300  		m,
   301  	)
   302  	return err
   303  }
   304  
   305  func (m *ChainHeight) UpdateByIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error {
   306  
   307  	if _, ok := fvs["UpdatedAt"]; !ok {
   308  		fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()}
   309  	}
   310  	tbl := db.T(m)
   311  	res, err := db.Exec(
   312  		builder.Update(tbl).
   313  			Where(
   314  				builder.And(
   315  					tbl.ColByFieldName("ID").Eq(m.ID),
   316  				),
   317  				builder.Comment("ChainHeight.UpdateByIDWithFVs"),
   318  			).
   319  			Set(tbl.AssignmentsByFieldValues(fvs)...),
   320  	)
   321  	if err != nil {
   322  		return err
   323  	}
   324  	if affected, _ := res.RowsAffected(); affected == 0 {
   325  		return m.FetchByID(db)
   326  	}
   327  	return nil
   328  }
   329  
   330  func (m *ChainHeight) UpdateByID(db sqlx.DBExecutor, zeros ...string) error {
   331  	fvs := builder.FieldValueFromStructByNoneZero(m, zeros...)
   332  	return m.UpdateByIDWithFVs(db, fvs)
   333  }
   334  
   335  func (m *ChainHeight) UpdateByChainHeightIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error {
   336  
   337  	if _, ok := fvs["UpdatedAt"]; !ok {
   338  		fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()}
   339  	}
   340  	tbl := db.T(m)
   341  	res, err := db.Exec(
   342  		builder.Update(tbl).
   343  			Where(
   344  				builder.And(
   345  					tbl.ColByFieldName("ChainHeightID").Eq(m.ChainHeightID),
   346  				),
   347  				builder.Comment("ChainHeight.UpdateByChainHeightIDWithFVs"),
   348  			).
   349  			Set(tbl.AssignmentsByFieldValues(fvs)...),
   350  	)
   351  	if err != nil {
   352  		return err
   353  	}
   354  	if affected, _ := res.RowsAffected(); affected == 0 {
   355  		return m.FetchByChainHeightID(db)
   356  	}
   357  	return nil
   358  }
   359  
   360  func (m *ChainHeight) UpdateByChainHeightID(db sqlx.DBExecutor, zeros ...string) error {
   361  	fvs := builder.FieldValueFromStructByNoneZero(m, zeros...)
   362  	return m.UpdateByChainHeightIDWithFVs(db, fvs)
   363  }
   364  
   365  func (m *ChainHeight) UpdateByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniqWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error {
   366  
   367  	if _, ok := fvs["UpdatedAt"]; !ok {
   368  		fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()}
   369  	}
   370  	tbl := db.T(m)
   371  	res, err := db.Exec(
   372  		builder.Update(tbl).
   373  			Where(
   374  				builder.And(
   375  					tbl.ColByFieldName("ProjectName").Eq(m.ProjectName),
   376  					tbl.ColByFieldName("EventType").Eq(m.EventType),
   377  					tbl.ColByFieldName("ChainID").Eq(m.ChainID),
   378  					tbl.ColByFieldName("ChainName").Eq(m.ChainName),
   379  					tbl.ColByFieldName("Height").Eq(m.Height),
   380  					tbl.ColByFieldName("Uniq").Eq(m.Uniq),
   381  				),
   382  				builder.Comment("ChainHeight.UpdateByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniqWithFVs"),
   383  			).
   384  			Set(tbl.AssignmentsByFieldValues(fvs)...),
   385  	)
   386  	if err != nil {
   387  		return err
   388  	}
   389  	if affected, _ := res.RowsAffected(); affected == 0 {
   390  		return m.FetchByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniq(db)
   391  	}
   392  	return nil
   393  }
   394  
   395  func (m *ChainHeight) UpdateByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniq(db sqlx.DBExecutor, zeros ...string) error {
   396  	fvs := builder.FieldValueFromStructByNoneZero(m, zeros...)
   397  	return m.UpdateByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniqWithFVs(db, fvs)
   398  }
   399  
   400  func (m *ChainHeight) Delete(db sqlx.DBExecutor) error {
   401  	_, err := db.Exec(
   402  		builder.Delete().
   403  			From(
   404  				db.T(m),
   405  				builder.Where(m.CondByValue(db)),
   406  				builder.Comment("ChainHeight.Delete"),
   407  			),
   408  	)
   409  	return err
   410  }
   411  
   412  func (m *ChainHeight) DeleteByID(db sqlx.DBExecutor) error {
   413  	tbl := db.T(m)
   414  	_, err := db.Exec(
   415  		builder.Delete().
   416  			From(
   417  				tbl,
   418  				builder.Where(
   419  					builder.And(
   420  						tbl.ColByFieldName("ID").Eq(m.ID),
   421  					),
   422  				),
   423  				builder.Comment("ChainHeight.DeleteByID"),
   424  			),
   425  	)
   426  	return err
   427  }
   428  
   429  func (m *ChainHeight) DeleteByChainHeightID(db sqlx.DBExecutor) error {
   430  	tbl := db.T(m)
   431  	_, err := db.Exec(
   432  		builder.Delete().
   433  			From(
   434  				tbl,
   435  				builder.Where(
   436  					builder.And(
   437  						tbl.ColByFieldName("ChainHeightID").Eq(m.ChainHeightID),
   438  					),
   439  				),
   440  				builder.Comment("ChainHeight.DeleteByChainHeightID"),
   441  			),
   442  	)
   443  	return err
   444  }
   445  
   446  func (m *ChainHeight) DeleteByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniq(db sqlx.DBExecutor) error {
   447  	tbl := db.T(m)
   448  	_, err := db.Exec(
   449  		builder.Delete().
   450  			From(
   451  				tbl,
   452  				builder.Where(
   453  					builder.And(
   454  						tbl.ColByFieldName("ProjectName").Eq(m.ProjectName),
   455  						tbl.ColByFieldName("EventType").Eq(m.EventType),
   456  						tbl.ColByFieldName("ChainID").Eq(m.ChainID),
   457  						tbl.ColByFieldName("ChainName").Eq(m.ChainName),
   458  						tbl.ColByFieldName("Height").Eq(m.Height),
   459  						tbl.ColByFieldName("Uniq").Eq(m.Uniq),
   460  					),
   461  				),
   462  				builder.Comment("ChainHeight.DeleteByProjectNameAndEventTypeAndChainIDAndChainNameAndHeightAndUniq"),
   463  			),
   464  	)
   465  	return err
   466  }