github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/databases/orm/db_dummy_orm.go (about) 1 // The original package is migrated from beego and modified, you can find orignal from following link: 2 // 3 // "github.com/beego/beego/" 4 // 5 // Copyright 2023 IAC. All Rights Reserved. 6 // 7 // Licensed under the Apache License, Version 2.0 (the "License"); 8 // you may not use this file except in compliance with the License. 9 // You may obtain a copy of the License at 10 // 11 // http://www.apache.org/licenses/LICENSE-2.0 12 // 13 // Unless required by applicable law or agreed to in writing, software 14 // distributed under the License is distributed on an "AS IS" BASIS, 15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 // See the License for the specific language governing permissions and 17 // limitations under the License. 18 package orm 19 20 import ( 21 "context" 22 "database/sql" 23 24 "github.com/mdaxf/iac/framework/utils" 25 ) 26 27 // DoNothingOrm won't do anything, usually you use this to custom your mock Ormer implementation 28 // I think golang mocking interface is hard to use 29 // this may help you to integrate with Ormer 30 31 var _ Ormer = new(DoNothingOrm) 32 33 type DoNothingOrm struct{} 34 35 func (d *DoNothingOrm) Read(md interface{}, cols ...string) error { 36 return nil 37 } 38 39 func (d *DoNothingOrm) ReadWithCtx(ctx context.Context, md interface{}, cols ...string) error { 40 return nil 41 } 42 43 func (d *DoNothingOrm) ReadForUpdate(md interface{}, cols ...string) error { 44 return nil 45 } 46 47 func (d *DoNothingOrm) ReadForUpdateWithCtx(ctx context.Context, md interface{}, cols ...string) error { 48 return nil 49 } 50 51 func (d *DoNothingOrm) ReadOrCreate(md interface{}, col1 string, cols ...string) (bool, int64, error) { 52 return false, 0, nil 53 } 54 55 func (d *DoNothingOrm) ReadOrCreateWithCtx(ctx context.Context, md interface{}, col1 string, cols ...string) (bool, int64, error) { 56 return false, 0, nil 57 } 58 59 func (d *DoNothingOrm) LoadRelated(md interface{}, name string, args ...utils.KV) (int64, error) { 60 return 0, nil 61 } 62 63 func (d *DoNothingOrm) LoadRelatedWithCtx(ctx context.Context, md interface{}, name string, args ...utils.KV) (int64, error) { 64 return 0, nil 65 } 66 67 func (d *DoNothingOrm) QueryM2M(md interface{}, name string) QueryM2Mer { 68 return nil 69 } 70 71 // NOTE: this method is deprecated, context parameter will not take effect. 72 func (d *DoNothingOrm) QueryM2MWithCtx(ctx context.Context, md interface{}, name string) QueryM2Mer { 73 return nil 74 } 75 76 func (d *DoNothingOrm) QueryTable(ptrStructOrTableName interface{}) QuerySeter { 77 return nil 78 } 79 80 // NOTE: this method is deprecated, context parameter will not take effect. 81 func (d *DoNothingOrm) QueryTableWithCtx(ctx context.Context, ptrStructOrTableName interface{}) QuerySeter { 82 return nil 83 } 84 85 func (d *DoNothingOrm) DBStats() *sql.DBStats { 86 return nil 87 } 88 89 func (d *DoNothingOrm) Insert(md interface{}) (int64, error) { 90 return 0, nil 91 } 92 93 func (d *DoNothingOrm) InsertWithCtx(ctx context.Context, md interface{}) (int64, error) { 94 return 0, nil 95 } 96 97 func (d *DoNothingOrm) InsertOrUpdate(md interface{}, colConflitAndArgs ...string) (int64, error) { 98 return 0, nil 99 } 100 101 func (d *DoNothingOrm) InsertOrUpdateWithCtx(ctx context.Context, md interface{}, colConflitAndArgs ...string) (int64, error) { 102 return 0, nil 103 } 104 105 func (d *DoNothingOrm) InsertMulti(bulk int, mds interface{}) (int64, error) { 106 return 0, nil 107 } 108 109 func (d *DoNothingOrm) InsertMultiWithCtx(ctx context.Context, bulk int, mds interface{}) (int64, error) { 110 return 0, nil 111 } 112 113 func (d *DoNothingOrm) Update(md interface{}, cols ...string) (int64, error) { 114 return 0, nil 115 } 116 117 func (d *DoNothingOrm) UpdateWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error) { 118 return 0, nil 119 } 120 121 func (d *DoNothingOrm) Delete(md interface{}, cols ...string) (int64, error) { 122 return 0, nil 123 } 124 125 func (d *DoNothingOrm) DeleteWithCtx(ctx context.Context, md interface{}, cols ...string) (int64, error) { 126 return 0, nil 127 } 128 129 func (d *DoNothingOrm) Raw(query string, args ...interface{}) RawSeter { 130 return nil 131 } 132 133 func (d *DoNothingOrm) RawWithCtx(ctx context.Context, query string, args ...interface{}) RawSeter { 134 return nil 135 } 136 137 func (d *DoNothingOrm) Driver() Driver { 138 return nil 139 } 140 141 func (d *DoNothingOrm) Begin() (TxOrmer, error) { 142 return nil, nil 143 } 144 145 func (d *DoNothingOrm) BeginWithCtx(ctx context.Context) (TxOrmer, error) { 146 return nil, nil 147 } 148 149 func (d *DoNothingOrm) BeginWithOpts(opts *sql.TxOptions) (TxOrmer, error) { 150 return nil, nil 151 } 152 153 func (d *DoNothingOrm) BeginWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions) (TxOrmer, error) { 154 return nil, nil 155 } 156 157 func (d *DoNothingOrm) DoTx(task func(ctx context.Context, txOrm TxOrmer) error) error { 158 return nil 159 } 160 161 func (d *DoNothingOrm) DoTxWithCtx(ctx context.Context, task func(ctx context.Context, txOrm TxOrmer) error) error { 162 return nil 163 } 164 165 func (d *DoNothingOrm) DoTxWithOpts(opts *sql.TxOptions, task func(ctx context.Context, txOrm TxOrmer) error) error { 166 return nil 167 } 168 169 func (d *DoNothingOrm) DoTxWithCtxAndOpts(ctx context.Context, opts *sql.TxOptions, task func(ctx context.Context, txOrm TxOrmer) error) error { 170 return nil 171 } 172 173 // DoNothingTxOrm is similar with DoNothingOrm, usually you use it to test 174 type DoNothingTxOrm struct { 175 DoNothingOrm 176 } 177 178 func (d *DoNothingTxOrm) Commit() error { 179 return nil 180 } 181 182 func (d *DoNothingTxOrm) Rollback() error { 183 return nil 184 }