// Code generated by gorm.io/gen. DO NOT EDIT. // Code generated by gorm.io/gen. DO NOT EDIT. // Code generated by gorm.io/gen. DO NOT EDIT. package query import ( "context" "database/sql" "gorm.io/gorm" "gorm.io/gen" "gorm.io/plugin/dbresolver" ) var ( Q = new(Query) Device *device DeviceMap *deviceMap MapUpdate *mapUpdate SimulationTestRecord *simulationTestRecord SystemConfig *systemConfig World *world ) func SetDefault(db *gorm.DB, opts ...gen.DOOption) { *Q = *Use(db, opts...) Device = &Q.Device DeviceMap = &Q.DeviceMap MapUpdate = &Q.MapUpdate SimulationTestRecord = &Q.SimulationTestRecord SystemConfig = &Q.SystemConfig World = &Q.World } func Use(db *gorm.DB, opts ...gen.DOOption) *Query { return &Query{ db: db, Device: newDevice(db, opts...), DeviceMap: newDeviceMap(db, opts...), MapUpdate: newMapUpdate(db, opts...), SimulationTestRecord: newSimulationTestRecord(db, opts...), SystemConfig: newSystemConfig(db, opts...), World: newWorld(db, opts...), } } type Query struct { db *gorm.DB Device device DeviceMap deviceMap MapUpdate mapUpdate SimulationTestRecord simulationTestRecord SystemConfig systemConfig World world } func (q *Query) Available() bool { return q.db != nil } func (q *Query) clone(db *gorm.DB) *Query { return &Query{ db: db, Device: q.Device.clone(db), DeviceMap: q.DeviceMap.clone(db), MapUpdate: q.MapUpdate.clone(db), SimulationTestRecord: q.SimulationTestRecord.clone(db), SystemConfig: q.SystemConfig.clone(db), World: q.World.clone(db), } } func (q *Query) ReadDB() *Query { return q.ReplaceDB(q.db.Clauses(dbresolver.Read)) } func (q *Query) WriteDB() *Query { return q.ReplaceDB(q.db.Clauses(dbresolver.Write)) } func (q *Query) ReplaceDB(db *gorm.DB) *Query { return &Query{ db: db, Device: q.Device.replaceDB(db), DeviceMap: q.DeviceMap.replaceDB(db), MapUpdate: q.MapUpdate.replaceDB(db), SimulationTestRecord: q.SimulationTestRecord.replaceDB(db), SystemConfig: q.SystemConfig.replaceDB(db), World: q.World.replaceDB(db), } } type queryCtx struct { Device IDeviceDo DeviceMap IDeviceMapDo MapUpdate IMapUpdateDo SimulationTestRecord ISimulationTestRecordDo SystemConfig ISystemConfigDo World IWorldDo } func (q *Query) WithContext(ctx context.Context) *queryCtx { return &queryCtx{ Device: q.Device.WithContext(ctx), DeviceMap: q.DeviceMap.WithContext(ctx), MapUpdate: q.MapUpdate.WithContext(ctx), SimulationTestRecord: q.SimulationTestRecord.WithContext(ctx), SystemConfig: q.SystemConfig.WithContext(ctx), World: q.World.WithContext(ctx), } } func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error { return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...) } func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx { tx := q.db.Begin(opts...) return &QueryTx{Query: q.clone(tx), Error: tx.Error} } type QueryTx struct { *Query Error error } func (q *QueryTx) Commit() error { return q.db.Commit().Error } func (q *QueryTx) Rollback() error { return q.db.Rollback().Error } func (q *QueryTx) SavePoint(name string) error { return q.db.SavePoint(name).Error } func (q *QueryTx) RollbackTo(name string) error { return q.db.RollbackTo(name).Error }