PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.0 KiB

package Database
import (
"database/sql"
"time"
_ "github.com/mattn/go-sqlite3"
)
func IsPackageInstalled(name, version string) (int64, error) {
var (
row *sql.Row
id int64
err error
)
row = DB.QueryRow(`
SELECT id FROM installed_packages WHERE name = ? AND version = ?;
`, name, version)
err = row.Scan(&id)
return id, err
}
func InsertPackage(name, version string, depIds []int64) error {
var (
stmt *sql.Stmt
result sql.Result
pkgId int64
depId int64
err error
)
stmt, err = DB.Prepare("INSERT INTO installed_packages(name, version, installed_at) VALUES(?,?,?)")
if err != nil {
return err
}
result, err = stmt.Exec(name, version, time.Now().Unix())
if err != nil {
return err
}
pkgId, err = result.LastInsertId()
if err != nil {
return err
}
for _, depId = range depIds {
stmt, err = DB.Prepare("INSERT INTO dependancy_linker(package_id, dependancy_id) VALUES(?,?)")
if err != nil {
return err
}
_, err = stmt.Exec(pkgId, depId)
if err != nil {
return err
}
}
return err
}