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.

61 lines
1023 B

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