Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
8c317fc3b6 | |||
efc047c965 | |||
5e9ba524e9 |
15
sqlite.go
15
sqlite.go
@@ -18,7 +18,6 @@ type database struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Database interface {
|
type Database interface {
|
||||||
Connect() error
|
|
||||||
Close() error
|
Close() error
|
||||||
Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
|
Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
|
||||||
Query(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
|
Query(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
|
||||||
@@ -43,19 +42,13 @@ func New(opts ...Option) (Database, error) {
|
|||||||
opt(db)
|
opt(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
return db, nil
|
slite, err := sqlx.Open("sqlite3", fmt.Sprintf("file:%s/%s", db.path, db.file))
|
||||||
}
|
|
||||||
|
|
||||||
// connects to database file
|
|
||||||
func (d *database) Connect() error {
|
|
||||||
db, err := sqlx.Open("sqlite3", fmt.Sprintf("file:%s/%s", d.path, d.file))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
db.sqlite = slite
|
||||||
|
|
||||||
d.sqlite = db
|
return db, nil
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// closes database file connection
|
// closes database file connection
|
||||||
|
Reference in New Issue
Block a user