You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
833 B
Go
36 lines
833 B
Go
package sqlite
|
|
|
|
import (
|
|
"git.phc.dm.unipi.it/phc/website/database"
|
|
"git.phc.dm.unipi.it/phc/website/util"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
type sqliteDBUploads struct{ *sqlx.DB }
|
|
|
|
var _ database.DBUploads = sqliteDBUploads{}
|
|
|
|
func (u sqliteDBUploads) Create(template database.Upload) (string, error) {
|
|
template.Id = "upload/" + util.GenerateRandomString(8)
|
|
|
|
if _, err := u.DB.NamedExec(`
|
|
INSERT INTO
|
|
uploads(id, created_at, owner_id, dispensa_id, file)
|
|
VALUES
|
|
(:id, :created_at, :owner_id, :dispensa_id, :file)
|
|
`, &template); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return template.Id, nil
|
|
}
|
|
|
|
func (u sqliteDBUploads) Get(id string) (database.Upload, error) {
|
|
var upload database.Upload
|
|
if err := u.DB.Select(`SELECT * FROM uploads WHERE id = ?`, id); err != nil {
|
|
return database.Upload{}, err
|
|
}
|
|
|
|
return upload, nil
|
|
}
|