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

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