3 Commits

Author SHA1 Message Date
8c317fc3b6 Merge pull request 'updating methods' (#1) from fix/connect-methodology into main
Reviewed-on: #1
2025-07-15 23:01:10 +00:00
efc047c965 updating methods
- removing connect method
- db is connected to on call to New
2025-07-15 19:00:33 -04:00
5e9ba524e9 adding better error handling around connections 2025-07-15 18:22:46 -04:00

View File

@@ -18,7 +18,6 @@ type database struct {
}
type Database interface {
Connect() error
Close() error
Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
Query(ctx context.Context, query string, args ...any) (*sqlx.Rows, error)
@@ -43,19 +42,13 @@ func New(opts ...Option) (Database, error) {
opt(db)
}
return db, nil
}
// connects to database file
func (d *database) Connect() error {
db, err := sqlx.Open("sqlite3", fmt.Sprintf("file:%s/%s", d.path, d.file))
slite, err := sqlx.Open("sqlite3", fmt.Sprintf("file:%s/%s", db.path, db.file))
if err != nil {
return err
return nil, err
}
db.sqlite = slite
d.sqlite = db
return nil
return db, nil
}
// closes database file connection