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 }