feat(server): CreateBatch/生成器切换到 codes 库(Mint 单事务全成或全无)(#codes-lib)
Store 挂库 store(NewStore 内部构造 libcodes.Store,签名不变); generator.go 三函数委托 libcodes,ErrDuplicate 别名同一哨兵; Service.CreateBatch 走 libcodes.Mint(签名不变)。openMigratedSQLite 挪到共享 sqlite_helper_test.go,backfill_test.go/service_sqlite_test.go 共用。Store.CreateBatch/CreateCode/CodeExistsByHash 原样保留供 webhook.go(Task 6 改用新原语,Task 7 删除)。
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
libcodes "github.com/wangjia/codes"
|
||||
dbx "github.com/wangjia/pangolin/server/internal/db"
|
||||
)
|
||||
|
||||
@@ -80,10 +81,21 @@ type BatchRow struct {
|
||||
type Store struct {
|
||||
db *sql.DB
|
||||
dialect dbx.Dialect
|
||||
lib *libcodes.Store
|
||||
}
|
||||
|
||||
// NewStore creates a Store backed by the given connection pool (MySQL or SQLite).
|
||||
func NewStore(db *sql.DB) *Store { return &Store{db: db, dialect: dbx.DialectForDB(db)} }
|
||||
func NewStore(db *sql.DB) *Store {
|
||||
d := dbx.DialectForDB(db)
|
||||
libD := libcodes.DialectMySQL
|
||||
if d.Name() == "sqlite" {
|
||||
libD = libcodes.DialectSQLite
|
||||
}
|
||||
return &Store{db: db, dialect: d, lib: libcodes.NewStore(db, libD)}
|
||||
}
|
||||
|
||||
// Lib exposes the shared library store (used by Service / webhook shim).
|
||||
func (s *Store) Lib() *libcodes.Store { return s.lib }
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Batch and code creation (used by Service.CreateBatch and webhook)
|
||||
|
||||
Reference in New Issue
Block a user