woodpecker/pkg/store/builtin/blob_sql.go
2015-06-13 17:37:36 -07:00

184 lines
2.6 KiB
Go

package builtin
// DO NOT EDIT
// code generated by go:generate
import (
"database/sql"
"encoding/json"
)
var _ = json.Marshal
// generic database interface, matching both *sql.Db and *sql.Tx
type blobDB interface {
Exec(query string, args ...interface{}) (sql.Result, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
}
func getBlob(db blobDB, query string, args ...interface{}) (*Blob, error) {
row := db.QueryRow(query, args...)
return scanBlob(row)
}
func getBlobs(db blobDB, query string, args ...interface{}) ([]*Blob, error) {
rows, err := db.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.Close()
return scanBlobs(rows)
}
func createBlob(db blobDB, query string, v *Blob) error {
var v0 string
var v1 []byte
v0 = v.Path
v1 = v.Data
res, err := db.Exec(query,
&v0,
&v1,
)
if err != nil {
return err
}
v.ID, err = res.LastInsertId()
return err
}
func updateBlob(db blobDB, query string, v *Blob) error {
var v0 int64
var v1 string
var v2 []byte
v0 = v.ID
v1 = v.Path
v2 = v.Data
_, err := db.Exec(query,
&v1,
&v2,
&v0,
)
return err
}
func scanBlob(row *sql.Row) (*Blob, error) {
var v0 int64
var v1 string
var v2 []byte
err := row.Scan(
&v0,
&v1,
&v2,
)
if err != nil {
return nil, err
}
v := &Blob{}
v.ID = v0
v.Path = v1
v.Data = v2
return v, nil
}
func scanBlobs(rows *sql.Rows) ([]*Blob, error) {
var err error
var vv []*Blob
for rows.Next() {
var v0 int64
var v1 string
var v2 []byte
err = rows.Scan(
&v0,
&v1,
&v2,
)
if err != nil {
return vv, err
}
v := &Blob{}
v.ID = v0
v.Path = v1
v.Data = v2
vv = append(vv, v)
}
return vv, rows.Err()
}
const stmtBlobSelectList = `
SELECT
blob_id
,blob_path
,blob_data
FROM blobs
`
const stmtBlobSelectRange = `
SELECT
blob_id
,blob_path
,blob_data
FROM blobs
LIMIT ? OFFSET ?
`
const stmtBlobSelect = `
SELECT
blob_id
,blob_path
,blob_data
FROM blobs
WHERE blob_id = ?
`
const stmtBlobSelectBlobPath = `
SELECT
blob_id
,blob_path
,blob_data
FROM blobs
WHERE blob_path = ?
`
const stmtBlobSelectCount = `
SELECT count(1)
FROM blobs
`
const stmtBlobInsert = `
INSERT INTO blobs (
blob_path
,blob_data
) VALUES (?,?);
`
const stmtBlobUpdate = `
UPDATE blobs SET
blob_path = ?
,blob_data = ?
WHERE blob_id = ?
`
const stmtBlobDelete = `
DELETE FROM blobs
WHERE blob_id = ?
`
const stmtBlobTable = `
CREATE TABLE IF NOT EXISTS blobs (
blob_id INTEGER PRIMARY KEY AUTOINCREMENT
,blob_path VARCHAR
,blob_data BLOB
);
`
const stmtBlobBlobPathIndex = `
CREATE UNIQUE INDEX IF NOT EXISTS ux_blob_path ON blobs (blob_path);
`