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 }