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

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