refactor(store): unify SQLite and Postgres into dialect-based SQLStore

Extract shared SQLStore with Dialect interface for the ~5% that
differs between backends (DDL, placeholders, sequence resets).

- New dialect.go: Dialect interface + placeholder rewriter (? → $N)
- New sqlstore.go: single implementation of all 19 Store methods
- sqlite.go: reduced from 286 to 83 lines (SQLiteDialect only)
- postgres.go: reduced from 266 to 78 lines (PostgresDialect only)
- main.go: use NewSQLiteStore/NewPostgresStore constructors

Zero CRUD logic duplication. Every future schema change written once.
This commit is contained in:
2026-05-15 00:31:44 -04:00
parent 4d5116644f
commit ab75f61c6b
5 changed files with 368 additions and 474 deletions
+8 -3
View File
@@ -80,16 +80,21 @@ func main() {
flag.Parse()
var s store.Store
var dbErr error
if *flagDBType == "postgres" {
s = &store.PostgresStore{ConnStr: *flagDSN}
s, dbErr = store.NewPostgresStore(*flagDSN)
fmt.Printf("Using PostgreSQL: %s\n", *flagDSN)
} else {
s = &store.SQLiteStore{DBPath: *flagDSN}
s, dbErr = store.NewSQLiteStore(*flagDSN)
fmt.Printf("Using SQLite: %s\n", *flagDSN)
}
if dbErr != nil {
fmt.Printf("Database connection error: %v\n", dbErr)
os.Exit(1)
}
if err := s.Init(); err != nil {
fmt.Printf("Database Init Error: %v\n", err)
fmt.Printf("Database init error: %v\n", err)
os.Exit(1)
}
store.SetGlobal(s)