Explorar el Código

删除dboperations

yjp hace 11 meses
padre
commit
c41a33d798

+ 0 - 93
db_operations/condition.go

@@ -1,93 +0,0 @@
-package db_operations
-
-import "gorm.io/gorm"
-
-type Conditions struct {
-	queries   []string
-	queryArgs [][]any
-}
-
-func NewConditions() *Conditions {
-	return &Conditions{
-		queries:   make([]string, 0),
-		queryArgs: make([][]any, 0),
-	}
-}
-
-func (clause *Conditions) Equal(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" = ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) Like(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" LIKE ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) In(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" IN ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) NotIn(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" NOT IN ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) Not(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" != ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) LessThan(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" < ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) LessThanAndEqual(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" <= ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) GreaterThan(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" > ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) GreaterThanAndEqual(columnName string, value any) *Conditions {
-	clause.queries = append(clause.queries, columnName+" >= ?")
-	clause.queryArgs = append(clause.queryArgs, []any{value})
-	return clause
-}
-
-func (clause *Conditions) where(db *gorm.DB) *gorm.DB {
-	for i, query := range clause.queries {
-		db = db.Where(query, clause.queryArgs[i]...)
-	}
-
-	return db
-}
-
-func (clause *Conditions) or(db *gorm.DB) *gorm.DB {
-	for i, query := range clause.queries {
-		db = db.Or(query, clause.queryArgs[i]...)
-	}
-
-	return db
-}
-
-func (clause *Conditions) having(db *gorm.DB) *gorm.DB {
-	for i, query := range clause.queries {
-		db = db.Having(query, clause.queryArgs[i]...)
-	}
-
-	return db
-}

+ 0 - 73
db_operations/db.go

@@ -1,73 +0,0 @@
-package db_operations
-
-import (
-	"errors"
-	"fmt"
-	"gorm.io/driver/postgres"
-	"gorm.io/gorm"
-	"gorm.io/gorm/logger"
-)
-
-const (
-	databaseTypePostgres = "postgres"
-)
-
-type DBConfig struct {
-	Type               string `mapstructure:"type"`
-	UserName           string `mapstructure:"user_name"`
-	Password           string `mapstructure:"password"`
-	Address            string `mapstructure:"address"`
-	Port               string `mapstructure:"port"`
-	Database           string `mapstructure:"database"`
-	MaxConnections     int    `mapstructure:"max_connections"`
-	MaxIdleConnections int    `mapstructure:"max_idle_connections"`
-}
-
-func newGormDB(dbConfig *DBConfig) (*gorm.DB, error) {
-	if dbConfig == nil {
-		return nil, errors.New("没有传递数据库配置")
-	}
-
-	var gormDB *gorm.DB
-
-	switch dbConfig.Type {
-	case databaseTypePostgres:
-		innerGormDB, err := newPostgresSQLOperationsItem(dbConfig)
-		if err != nil {
-			return nil, err
-		}
-
-		gormDB = innerGormDB
-	default:
-		innerGormDB, err := newPostgresSQLOperationsItem(dbConfig)
-		if err != nil {
-			return nil, err
-		}
-
-		gormDB = innerGormDB
-	}
-
-	return gormDB, nil
-}
-
-func newPostgresSQLOperationsItem(dbConfig *DBConfig) (*gorm.DB, error) {
-	dsn := "host=%s port=%s user=%s password=%s dbname=%s sslmode=disable TimeZone=Asia/Shanghai"
-	connStr := fmt.Sprintf(dsn, dbConfig.Address, dbConfig.Port, dbConfig.UserName, dbConfig.Password, dbConfig.Database)
-	return gorm.Open(postgres.Open(connStr), &gorm.Config{
-		Logger:      logger.Default.LogMode(logger.Info),
-		PrepareStmt: true,
-	})
-}
-
-func destroyGormDB(gormDB *gorm.DB) error {
-	if gormDB == nil {
-		return nil
-	}
-
-	db, err := gormDB.DB()
-	if err != nil {
-		return err
-	}
-
-	return db.Close()
-}

+ 0 - 61
db_operations/db_operations.go

@@ -1,61 +0,0 @@
-package db_operations
-
-type DBOperations interface {
-	BeginTransaction() TransactionDBOperations
-	// BeginEvent() EventDBOperations
-	BaseDBOperations
-}
-
-type TransactionDBOperations interface {
-	BaseDBOperations
-	RollbackTransaction()
-	CommitTransaction()
-}
-
-type EventDBOperations interface {
-	RollbackEvent()
-	CommitEvent()
-	// TODO 需要重新定义创建等方法,传递必要的key
-	EventRows(table string, keys []string, pageSize int, pageNo string)
-	Replay(table string, keys []string)
-}
-
-type BaseDBOperations interface {
-	// 会重置数据库连接的方法
-	Table(name string, args ...any) DBOperations
-
-	// 会重置数据库连接的方法,一般配合Raw使用
-	NewSession() DBOperations
-
-	// 执行SQL语句,使用Raw之后,为了触发SQL执行,需要调用Row或者Rows
-	// 如果是查询语句,使用Rows或Row均可,主要看自己需要查询的是单行还是多行
-	// 如果是写语句,必须使用Rows,否则由于没有返回结果,Rows会报错
-	// 使用Raw以后,所有分页相关的参数都无效,需要使用SQL语句进行分页
-	Raw(sql string, values ...any) DBOperations
-
-	// 组织SQL语句相关的方法
-	Select(query string, args ...any) DBOperations
-	Joins(query string, args ...any) DBOperations
-	Where(conditions *Conditions) DBOperations
-	Or(conditions *Conditions) DBOperations
-	Having(conditions *Conditions) DBOperations
-	GroupBy(groupBy string) DBOperations
-	OrderBy(orderBy string) DBOperations
-	Paging(pageNo int, pageSize int) DBOperations
-
-	// 写方法
-	Create(tableRow *TableRow) error
-	CreateBatch(tableRows []TableRow) error
-	Delete() error
-	Updates(newTableRow *TableRow) error
-	UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error)
-
-	// 查询方法
-	Rows(pageNo int, pageSize int) ([]TableRow, error)
-	Row() (*TableRow, error)
-
-	// 其他方法
-	Count(count *int64) error
-	CheckExist() (bool, error)
-	CheckHasOnlyOne() (bool, error)
-}

+ 0 - 19
db_operations/dberr.go

@@ -1,19 +0,0 @@
-package db_operations
-
-import (
-	"errors"
-	"strings"
-)
-
-var (
-	ErrDBRecordHasExist = errors.New("记录已存在")
-	ErrDBRecordNotExist = errors.New("记录不存在")
-)
-
-func IsErrorDBRecordHasExist(err error) bool {
-	return strings.Contains(err.Error(), "记录已存在")
-}
-
-func IsErrorDBRecordNotExist(err error) bool {
-	return strings.Contains(err.Error(), "记录不存在")
-}

+ 0 - 297
db_operations/operations.go

@@ -1,297 +0,0 @@
-package db_operations
-
-import (
-	"database/sql"
-	"git.sxidc.com/service-supports/fslog"
-	"github.com/mitchellh/mapstructure"
-	"gorm.io/gorm"
-	"strings"
-	"time"
-)
-
-type Operations struct {
-	initDB       *gorm.DB
-	processDB    *gorm.DB
-	stopPingChan chan any
-}
-
-func NewOperationsFromMap(configMap map[string]any) (*Operations, error) {
-	dbConfig := new(DBConfig)
-	err := mapstructure.Decode(configMap, dbConfig)
-	if err != nil {
-		return nil, err
-	}
-
-	return NewOperations(dbConfig)
-}
-
-func NewOperations(dbConfig *DBConfig) (*Operations, error) {
-	gormDB, err := newGormDB(dbConfig)
-	if err != nil {
-		return nil, err
-	}
-
-	sqlDB, err := gormDB.DB()
-	if err != nil {
-		return nil, err
-	}
-
-	if dbConfig.MaxConnections == 0 {
-		dbConfig.MaxConnections = 50
-	}
-
-	if dbConfig.MaxIdleConnections == 0 {
-		dbConfig.MaxIdleConnections = 10
-	}
-
-	sqlDB.SetMaxOpenConns(dbConfig.MaxConnections)
-	sqlDB.SetMaxIdleConns(dbConfig.MaxIdleConnections)
-
-	op := &Operations{
-		initDB:       gormDB,
-		processDB:    gormDB,
-		stopPingChan: make(chan any),
-	}
-
-	op.startBeatHeart(sqlDB)
-
-	return op, nil
-}
-
-func DestroyOperation(op *Operations) error {
-	if op == nil {
-		return nil
-	}
-
-	if op.initDB == nil {
-		return nil
-	}
-
-	op.stopBeatHeart()
-
-	return destroyGormDB(op.initDB)
-}
-
-func (op *Operations) startBeatHeart(sqlDB *sql.DB) {
-	go func() {
-		pingTicker := time.NewTicker(time.Minute * 1)
-		defer pingTicker.Stop()
-
-		for {
-			select {
-			case <-op.stopPingChan:
-				return
-			case <-pingTicker.C:
-				err := sqlDB.Ping()
-				if err != nil {
-					fslog.Error(err)
-				}
-			}
-		}
-	}()
-}
-
-func (op *Operations) stopBeatHeart() {
-	if op.stopPingChan != nil {
-		close(op.stopPingChan)
-		op.stopPingChan = nil
-	}
-}
-
-func (op *Operations) BeginTransaction() TransactionDBOperations {
-	tx := op.initDB.Begin()
-	return &TransactionOperations{
-		Operations{
-			initDB:    tx,
-			processDB: tx,
-		},
-	}
-}
-
-func (op *Operations) NewSession() DBOperations {
-	return &Operations{
-		initDB:    op.initDB,
-		processDB: op.initDB,
-	}
-}
-
-func (op *Operations) Table(name string, args ...any) DBOperations {
-	op.processDB = op.initDB.Table(name, args...)
-	return op
-}
-
-func (op *Operations) Raw(sql string, values ...any) DBOperations {
-	op.processDB = op.processDB.Raw(sql, values...)
-	return op
-}
-
-func (op *Operations) Select(query string, args ...any) DBOperations {
-	op.processDB = op.processDB.Select(query, args...)
-	return op
-}
-
-func (op *Operations) Joins(query string, args ...any) DBOperations {
-	op.processDB = op.processDB.Joins(query, args...)
-	return op
-}
-
-func (op *Operations) Where(conditions *Conditions) DBOperations {
-	op.processDB = conditions.where(op.processDB)
-	return op
-}
-
-func (op *Operations) Or(conditions *Conditions) DBOperations {
-	op.processDB = conditions.or(op.processDB)
-	return op
-}
-
-func (op *Operations) Having(conditions *Conditions) DBOperations {
-	op.processDB = conditions.having(op.processDB)
-	return op
-}
-
-func (op *Operations) GroupBy(groupBy string) DBOperations {
-	op.processDB = op.processDB.Group(groupBy)
-	return op
-}
-
-func (op *Operations) OrderBy(orderBy string) DBOperations {
-	op.processDB = op.processDB.Order(orderBy)
-	return op
-}
-
-func (op *Operations) Paging(pageNo int, pageSize int) DBOperations {
-	if pageNo != 0 && pageSize != 0 {
-		offset := -1
-
-		if pageNo == -1 || pageSize == -1 {
-			offset = -1
-			pageSize = -1
-		} else {
-			offset = (pageNo - 1) * pageSize
-		}
-
-		op.processDB = op.processDB.Offset(offset).Limit(pageSize)
-	}
-
-	return op
-}
-
-func (op *Operations) Create(tableRow *TableRow) error {
-	err := op.processDB.Create(tableRow.ToMap()).Error
-	if err != nil {
-		if strings.Contains(err.Error(), "SQLSTATE 23505") {
-			return ErrDBRecordHasExist
-		}
-
-		return err
-	}
-
-	return nil
-}
-
-func (op *Operations) CreateBatch(tableRows []TableRow) error {
-	tableRowMaps := make([]map[string]any, 0)
-	for _, tableRow := range tableRows {
-		tableRowMaps = append(tableRowMaps, tableRow.ToMap())
-	}
-
-	err := op.processDB.Create(tableRowMaps).Error
-	if err != nil {
-		if strings.Contains(err.Error(), "SQLSTATE 23505") {
-			return ErrDBRecordHasExist
-		}
-
-		return err
-	}
-
-	return nil
-}
-
-func (op *Operations) Delete() error {
-	return op.processDB.Delete(make(map[string]any)).Error
-}
-
-func (op *Operations) Updates(newTableRow *TableRow) error {
-	err := op.processDB.Updates(newTableRow.ToMap()).Error
-	if err != nil {
-		if strings.Contains(err.Error(), "SQLSTATE 23505") {
-			return ErrDBRecordHasExist
-		}
-
-		return err
-	}
-
-	return nil
-}
-
-func (op *Operations) UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error) {
-	op.processDB = op.processDB.Updates(newTableRow.ToMap())
-	if op.processDB.Error != nil {
-		return 0, op.processDB.Error
-	}
-
-	return op.processDB.RowsAffected, nil
-}
-
-func (op *Operations) Rows(pageNo int, pageSize int) ([]TableRow, error) {
-	if pageNo != 0 && pageSize != 0 {
-		offset := (pageNo - 1) * pageSize
-		op.processDB = op.processDB.Offset(offset).Limit(pageSize)
-	}
-
-	defer func() {
-		op.processDB = op.processDB.Offset(-1).Limit(-1)
-	}()
-
-	tableRowMaps := make([]map[string]any, 0)
-	err := op.processDB.Scan(&tableRowMaps).Error
-	if err != nil {
-		return nil, err
-	}
-
-	tableRows := make([]TableRow, 0)
-	for _, tableRowMap := range tableRowMaps {
-		tableRows = append(tableRows, *NewTableRowFromMap(tableRowMap))
-	}
-
-	return tableRows, nil
-}
-
-func (op *Operations) Row() (*TableRow, error) {
-	valueMap := make(map[string]any)
-	err := op.processDB.Scan(&valueMap).Error
-	if err != nil {
-		return nil, err
-	}
-
-	if valueMap == nil || len(valueMap) == 0 {
-		return nil, ErrDBRecordNotExist
-	}
-
-	return NewTableRowFromMap(valueMap), nil
-}
-
-func (op *Operations) Count(count *int64) error {
-	return op.processDB.Count(count).Error
-}
-
-func (op *Operations) CheckExist() (bool, error) {
-	var count int64
-	err := op.processDB.Count(&count).Error
-	if err != nil {
-		return false, err
-	}
-
-	return count > 0, nil
-}
-
-func (op *Operations) CheckHasOnlyOne() (bool, error) {
-	var count int64
-	err := op.processDB.Count(&count).Error
-	if err != nil {
-		return false, err
-	}
-
-	return count == 1, nil
-}

+ 0 - 302
db_operations/table_row.go

@@ -1,302 +0,0 @@
-package db_operations
-
-import (
-	"reflect"
-	"time"
-)
-
-type TableRow struct {
-	row map[string]any
-}
-
-func NewTableRow() *TableRow {
-	return &TableRow{row: make(map[string]any)}
-}
-
-func NewTableRowFromMap(m map[string]any) *TableRow {
-	tableRow := NewTableRow()
-
-	for key, value := range m {
-		v := value
-
-		valueType := reflect.TypeOf(value)
-		if valueType.Kind() == reflect.Ptr {
-			v = reflect.ValueOf(value).Elem().Interface()
-		}
-
-		switch typedValue := v.(type) {
-		case string:
-			tableRow.row[key] = typedValue
-		case int:
-			tableRow.row[key] = uint64(typedValue)
-		case uint:
-			tableRow.row[key] = uint64(typedValue)
-		case int8:
-			tableRow.row[key] = uint64(typedValue)
-		case uint8:
-			tableRow.row[key] = uint64(typedValue)
-		case int16:
-			tableRow.row[key] = uint64(typedValue)
-		case uint16:
-			tableRow.row[key] = uint64(typedValue)
-		case int32:
-			tableRow.row[key] = uint64(typedValue)
-		case uint32:
-			tableRow.row[key] = uint64(typedValue)
-		case int64:
-			tableRow.row[key] = uint64(typedValue)
-		case uint64:
-			tableRow.row[key] = typedValue
-		case float32:
-			tableRow.row[key] = float64(typedValue)
-		case float64:
-			tableRow.row[key] = typedValue
-		case bool:
-			tableRow.row[key] = typedValue
-		case []byte:
-			tableRow.row[key] = typedValue
-		case time.Time:
-			tableRow.row[key] = typedValue
-		default:
-			panic("未支持的数据类型")
-		}
-	}
-
-	return tableRow
-}
-
-func (tableRow *TableRow) ToMap() map[string]any {
-	return tableRow.row
-}
-
-func (tableRow *TableRow) Len() int {
-	return len(tableRow.row)
-}
-
-func (tableRow *TableRow) Empty() bool {
-	return len(tableRow.row) == 0
-}
-
-func (tableRow *TableRow) AddColumnValueTime(columnName string, value time.Time) *TableRow {
-	tableRow.row[columnName] = value
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueBool(columnName string, value bool) *TableRow {
-	tableRow.row[columnName] = value
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueString(columnName string, value string) *TableRow {
-	tableRow.row[columnName] = value
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueBytes(columnName string, value []byte) *TableRow {
-	tableRow.row[columnName] = value
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueInt(columnName string, value int) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueInt8(columnName string, value int8) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueInt16(columnName string, value int16) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueInt32(columnName string, value int32) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueInt64(columnName string, value int64) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueUint(columnName string, value uint) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueUint8(columnName string, value uint8) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueUint16(columnName string, value uint16) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueUint32(columnName string, value uint32) *TableRow {
-	tableRow.row[columnName] = uint64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueUint64(columnName string, value uint64) *TableRow {
-	tableRow.row[columnName] = value
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueFloat32(columnName string, value float32) *TableRow {
-	tableRow.row[columnName] = float64(value)
-	return tableRow
-}
-
-func (tableRow *TableRow) AddColumnValueFloat64(columnName string, value float64) *TableRow {
-	tableRow.row[columnName] = value
-	return tableRow
-}
-
-func (tableRow *TableRow) ColumnValueTime(columnName string) time.Time {
-	value, ok := tableRow.row[columnName].(time.Time)
-	if !ok {
-		return time.Time{}
-	}
-
-	return value
-}
-
-func (tableRow *TableRow) ColumnValueBool(columnName string) bool {
-	value, ok := tableRow.row[columnName].(bool)
-	if !ok {
-		return false
-	}
-
-	return value
-}
-
-func (tableRow *TableRow) ColumnValueString(columnName string) string {
-	value, ok := tableRow.row[columnName].(string)
-	if !ok {
-		return ""
-	}
-
-	return value
-}
-
-func (tableRow *TableRow) ColumnValueBytes(columnName string) []byte {
-	value, ok := tableRow.row[columnName].([]byte)
-	if !ok {
-		return make([]byte, 0)
-	}
-
-	return value
-}
-
-func (tableRow *TableRow) ColumnValueInt(columnName string) int {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return int(value)
-}
-
-func (tableRow *TableRow) ColumnValueInt8(columnName string) int8 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return int8(value)
-}
-
-func (tableRow *TableRow) ColumnValueInt16(columnName string) int16 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return int16(value)
-}
-
-func (tableRow *TableRow) ColumnValueInt32(columnName string) int32 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return int32(value)
-}
-
-func (tableRow *TableRow) ColumnValueInt64(columnName string) int64 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return int64(value)
-}
-
-func (tableRow *TableRow) ColumnValueUint(columnName string) uint {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return uint(value)
-}
-
-func (tableRow *TableRow) ColumnValueUint8(columnName string) uint8 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return uint8(value)
-}
-
-func (tableRow *TableRow) ColumnValueUint16(columnName string) uint16 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return uint16(value)
-}
-
-func (tableRow *TableRow) ColumnValueUint32(columnName string) uint32 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return uint32(value)
-}
-
-func (tableRow *TableRow) ColumnValueUint64(columnName string) uint64 {
-	value, ok := tableRow.row[columnName].(uint64)
-	if !ok {
-		return 0
-	}
-
-	return value
-}
-
-func (tableRow *TableRow) ColumnValueFloat32(columnName string) float32 {
-	value, ok := tableRow.row[columnName].(float64)
-	if !ok {
-		return 0
-	}
-
-	return float32(value)
-}
-
-func (tableRow *TableRow) ColumnValueFloat64(columnName string) float64 {
-	value, ok := tableRow.row[columnName].(float64)
-	if !ok {
-		return 0
-	}
-
-	return value
-}

+ 0 - 21
db_operations/transaction_operations.go

@@ -1,21 +0,0 @@
-package db_operations
-
-type TransactionOperations struct {
-	Operations
-}
-
-func (op *TransactionOperations) RollbackTransaction() {
-	defer func() {
-		op.processDB = op.initDB
-	}()
-
-	op.processDB.Rollback()
-}
-
-func (op *TransactionOperations) CommitTransaction() {
-	defer func() {
-		op.processDB = op.initDB
-	}()
-
-	op.processDB.Commit()
-}

+ 0 - 94
demo/demo.go

@@ -2,9 +2,7 @@ package main
 
 import (
 	"git.sxidc.com/go-tools/utils/strutils"
-	"git.sxidc.com/service-supports/ds-sdk/db_operations"
 	"git.sxidc.com/service-supports/ds-sdk/sdk"
-	"math/rand"
 )
 
 const (
@@ -49,15 +47,6 @@ var (
 
 func main() {
 	classID1 := strutils.SimpleUUID()
-	className1 := strutils.SimpleUUID()
-	studentNum1 := rand.Int31n(100)
-
-	newClassName1 := strutils.SimpleUUID()
-	newStudentNum1 := rand.Int31n(100)
-
-	classID2 := strutils.SimpleUUID()
-	className2 := strutils.SimpleUUID()
-	studentNum2 := rand.Int31n(100)
 
 	err := sdk.InitInstance(token, baseUrl, namespace, dataSource)
 	if err != nil {
@@ -76,89 +65,6 @@ func main() {
 		panic(err)
 	}
 
-	err = sdk.GetInstance().GetDBOperations().
-		Table("test.classes").
-		Create(db_operations.NewTableRowFromMap(map[string]any{
-			"id":          classID1,
-			"name":        className1,
-			"student_num": studentNum1,
-		}))
-	if err != nil {
-		panic(err)
-	}
-
-	err = sdk.GetInstance().GetDBOperations().
-		Table("test.classes").
-		Where(db_operations.NewConditions().Equal("id", classID1)).
-		Delete()
-	if err != nil {
-		panic(err)
-	}
-
-	err = sdk.GetInstance().GetDBOperations().
-		Table("test.classes").
-		CreateBatch([]db_operations.TableRow{
-			*db_operations.NewTableRow().
-				AddColumnValueString("id", classID1).
-				AddColumnValueString("name", className1).
-				AddColumnValueInt32("student_num", studentNum1),
-			*db_operations.NewTableRowFromMap(map[string]any{
-				"id":          classID2,
-				"name":        className2,
-				"student_num": studentNum2,
-			}),
-		})
-	if err != nil {
-		panic(err)
-	}
-
-	tx := sdk.GetInstance().GetDBOperations().BeginTransaction()
-
-	_, err = tx.
-		Raw("UPDATE test.classes SET name = ?, student_num = ? WHERE id = ?", newClassName1, newStudentNum1, classID1).
-		Rows(0, 0)
-	if err != nil {
-		tx.RollbackTransaction()
-		panic(err)
-	}
-
-	tx.CommitTransaction()
-
-	tableRow, err := sdk.GetInstance().GetDBOperations().
-		Table("test.classes").
-		Where(db_operations.NewConditions().Equal("id", classID1)).
-		Row()
-	if err != nil {
-		panic(err)
-	}
-
-	if tableRow.ColumnValueString("id") != classID1 ||
-		tableRow.ColumnValueString("name") != newClassName1 ||
-		tableRow.ColumnValueInt32("student_num") != newStudentNum1 {
-		panic("数据查询错误")
-	}
-
-	tableRows, err := sdk.GetInstance().GetDBOperations().NewSession().
-		Raw("SELECT * FROM test.classes LIMIT 1 OFFSET 1").
-		Rows(0, 0)
-	if err != nil {
-		panic(err)
-	}
-
-	for _, tableRow := range tableRows {
-		if tableRow.ColumnValueString("id") == classID1 {
-			if tableRow.ColumnValueString("name") != newClassName1 ||
-				tableRow.ColumnValueInt32("student_num") != newStudentNum1 {
-				panic("数据查询错误")
-			}
-		} else {
-			if tableRow.ColumnValueString("name") != className2 ||
-				tableRow.ColumnValueInt32("student_num") != studentNum2 {
-				panic("数据查询错误")
-			}
-		}
-	}
-
 	err = sdk.GetInstance().CreateSQL(sql, sqlSpec.ToMap())
 	if err != nil {
 		panic(err)

+ 2 - 46
sdk/instance.go

@@ -1,10 +1,7 @@
 package sdk
 
 import (
-	"encoding/json"
-	"errors"
 	"git.sxidc.com/service-supports/ds-sdk/client"
-	"git.sxidc.com/service-supports/ds-sdk/db_operations"
 )
 
 var sdkInstance *SDK
@@ -31,60 +28,19 @@ func InitInstance(token string, baseUrl string, namespace string, dataSource str
 
 	c := client.New(options.timeout)
 
-	dbOperations, err := initDBOperations(c, options)
-	if err != nil {
-		return err
-	}
-
 	sdkInstance = &SDK{
-		options:      options,
-		client:       c,
-		dbOperations: dbOperations,
+		options: options,
+		client:  c,
 	}
 
 	return nil
 }
 
-func initDBOperations(c *client.Client, options *Options) (db_operations.DBOperations, error) {
-	dataSourceInfo, err := c.GetDataSources(options.token, options.baseUrl, options.namespace, options.dataSource,
-		"database", 0, 0)
-	if err != nil {
-		return nil, err
-	}
-
-	if dataSourceInfo == nil || len(dataSourceInfo) == 0 {
-		return nil, errors.New("不存在类型为database的数据源" + options.dataSource)
-	}
-
-	specStr, err := c.GetDataSourceSpec(options.token, options.baseUrl, options.namespace, options.dataSource)
-	if err != nil {
-		return nil, err
-	}
-
-	specMap := make(map[string]any)
-	err = json.Unmarshal([]byte(specStr), &specMap)
-	if err != nil {
-		return nil, err
-	}
-
-	dbOperations, err := db_operations.NewOperationsFromMap(specMap)
-	if err != nil {
-		return nil, err
-	}
-
-	return dbOperations, nil
-}
-
 func DestroyInstance() error {
 	if sdkInstance == nil {
 		return nil
 	}
 
-	err := db_operations.DestroyOperation(sdkInstance.dbOperations.(*db_operations.Operations))
-	if err != nil {
-		return err
-	}
-
 	sdkInstance = nil
 
 	return nil

+ 2 - 8
sdk/sdk.go

@@ -4,17 +4,11 @@ import (
 	"errors"
 	"git.sxidc.com/go-tools/utils/strutils"
 	"git.sxidc.com/service-supports/ds-sdk/client"
-	"git.sxidc.com/service-supports/ds-sdk/db_operations"
 )
 
 type SDK struct {
-	options      *Options
-	client       *client.Client
-	dbOperations db_operations.DBOperations
-}
-
-func (s *SDK) GetDBOperations() db_operations.DBOperations {
-	return s.dbOperations
+	options *Options
+	client  *client.Client
 }
 
 func (s *SDK) CreateDataContainer(name string, spec map[string]any) error {