fix: sdbc to Driver

This commit is contained in:
xuthus5 2023-09-16 20:21:42 +08:00
parent 108f62aa4d
commit e63125d1d5
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
7 changed files with 15 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import (
type _delete struct { type _delete struct {
scope *scope scope *scope
sdbc *sdbc sdbc *Driver
ctx context.Context ctx context.Context
where []any where []any
isHard bool isHard bool

View File

@ -8,7 +8,7 @@ import (
type _find struct { type _find struct {
scope *scope scope *scope
sdbc *sdbc sdbc *Driver
ctx context.Context ctx context.Context
where []any where []any
selectOpts []interface{} selectOpts []interface{}

View File

@ -4,7 +4,7 @@ import "context"
type _insert struct { type _insert struct {
scope *scope scope *scope
sdbc *sdbc sdbc *Driver
ctx context.Context ctx context.Context
selectOpts []interface{} selectOpts []interface{}
omitOpts []string omitOpts []string

View File

@ -141,7 +141,7 @@ func file_model_proto_rawDescGZIP() []byte {
var file_model_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_model_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_model_proto_goTypes = []interface{}{ var file_model_proto_goTypes = []interface{}{
(*ModelArticles)(nil), // 0: sdbc.ModelArticles (*ModelArticles)(nil), // 0: Driver.ModelArticles
} }
var file_model_proto_depIdxs = []int32{ var file_model_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type 0, // [0:0] is the sub-list for method output_type

View File

@ -21,34 +21,34 @@ func (m *model) ptr() any {
type scope struct { type scope struct {
*model *model
*sdbc *Driver
} }
func (s *scope) Insert() *_insert { func (s *scope) Insert() *_insert {
return &_insert{ return &_insert{
scope: s, scope: s,
sdbc: s.sdbc, sdbc: s.Driver,
} }
} }
func (s *scope) Find() *_find { func (s *scope) Find() *_find {
return &_find{ return &_find{
scope: s, scope: s,
sdbc: s.sdbc, sdbc: s.Driver,
} }
} }
func (s *scope) Update() *_update { func (s *scope) Update() *_update {
return &_update{ return &_update{
scope: s, scope: s,
sdbc: s.sdbc, sdbc: s.Driver,
} }
} }
func (s *scope) Delete() *_delete { func (s *scope) Delete() *_delete {
return &_delete{ return &_delete{
scope: s, scope: s,
sdbc: s.sdbc, sdbc: s.Driver,
} }
} }

10
sdbc.go
View File

@ -29,17 +29,17 @@ type Config struct {
Debug bool // 是否开启debug Debug bool // 是否开启debug
} }
type sdbc struct { type Driver struct {
dbname string dbname string
client *gorm.DB client *gorm.DB
} }
func NewSDBC(cfg *Config) *sdbc { func NewSDBC(cfg *Config) *Driver {
if cfg == nil { if cfg == nil {
logrus.Fatalf("config can not be nil") logrus.Fatalf("config can not be nil")
} }
var ( var (
driver = new(sdbc) driver = new(Driver)
err error err error
) )
driver.client, err = gorm.Open(sqlite.Open(cfg.Dbname), &gorm.Config{}) driver.client, err = gorm.Open(sqlite.Open(cfg.Dbname), &gorm.Config{})
@ -66,11 +66,11 @@ func NewSDBC(cfg *Config) *sdbc {
return driver return driver
} }
func (s *sdbc) GetClient() *gorm.DB { func (s *Driver) GetClient() *gorm.DB {
return s.client return s.client
} }
func (s *sdbc) BindModel(prototype any) Operator { func (s *Driver) BindModel(prototype any) Operator {
if prototype == nil { if prototype == nil {
logrus.Panic("model can not be nil") logrus.Panic("model can not be nil")
} }

View File

@ -7,7 +7,7 @@ import (
type _update struct { type _update struct {
scope *scope scope *scope
sdbc *sdbc sdbc *Driver
ctx context.Context ctx context.Context
where []any where []any
selectOpts []interface{} selectOpts []interface{}