This commit is contained in:
2023-08-07 10:14:38 -04:00
parent a30b1769b3
commit 5dd3fa9451
18 changed files with 548 additions and 276 deletions

View File

@@ -3,17 +3,19 @@ package sql
import (
"context"
"database/sql"
sqlc "git.siteworxpro.com/gun-manager/sql/db"
_ "github.com/mattn/go-sqlite3"
)
type SqlDb struct {
type Db struct {
db *sql.DB
created bool
Queries *sqlc.Queries
}
var dbConnection SqlDb
var dbConnection Db
func NewDb(file string) (*SqlDb, error) {
func NewDb(file string) (*Db, error) {
if dbConnection.created {
return &dbConnection, nil
}
@@ -31,9 +33,11 @@ func NewDb(file string) (*SqlDb, error) {
return nil, err
}
dbConnection.Queries = sqlc.New(db)
return &dbConnection, nil
}
func GetDb() *SqlDb {
func GetDb() *Db {
return &dbConnection
}