mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-24 08:19:27 +00:00
added blobstore and capability packages
This commit is contained in:
9
server/blobstore/blobsql/blob.go
Normal file
9
server/blobstore/blobsql/blob.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package blobsql
|
||||
|
||||
type Blob struct {
|
||||
ID int64 `meddler:"blob_id,pk" orm:"column(blob_id);pk;auto"`
|
||||
Path string `meddler:"blob_path" orm:"column(blob_path);size(2000);unique"`
|
||||
Data string `meddler:"blob_data,gobgzip" orm:"column(blob_data);type(text)"`
|
||||
}
|
||||
|
||||
func (b *Blob) TableName() string { return "blobs" }
|
||||
55
server/blobstore/blobsql/blobstore.go
Normal file
55
server/blobstore/blobsql/blobstore.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package blobsql
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
|
||||
type Blobstore struct {
|
||||
meddler.DB
|
||||
}
|
||||
|
||||
// Del removes an object from the blobstore.
|
||||
func (b *Blobstore) Del(path string) error {
|
||||
var _, err = b.Exec(deleteBlob, path)
|
||||
return err
|
||||
}
|
||||
|
||||
// Get retrieves an object from the blobstore.
|
||||
func (b *Blobstore) Get(path string) ([]byte, error) {
|
||||
var blob = Blob{}
|
||||
var err = meddler.QueryRow(b, &blob, queryBlob, path)
|
||||
return []byte(blob.Data), err
|
||||
}
|
||||
|
||||
// GetReader retrieves an object from the blobstore.
|
||||
// It is the caller's responsibility to call Close on
|
||||
// the ReadCloser when finished reading.
|
||||
func (b *Blobstore) GetReader(path string) (io.ReadCloser, error) {
|
||||
var blob, err = b.Get(path)
|
||||
var buf = bytes.NewBuffer(blob)
|
||||
return ioutil.NopCloser(buf), err
|
||||
}
|
||||
|
||||
// Put inserts an object into the blobstore.
|
||||
func (b *Blobstore) Put(path string, data []byte) error {
|
||||
var blob = Blob{}
|
||||
meddler.QueryRow(b, &blob, queryBlob, path)
|
||||
blob.Path = path
|
||||
blob.Data = string(data)
|
||||
return meddler.Save(b, tableBlob, &blob)
|
||||
}
|
||||
|
||||
// PutReader inserts an object into the blobstore by
|
||||
// consuming data from r until EOF.
|
||||
func (b *Blobstore) PutReader(path string, r io.Reader) error {
|
||||
var data, _ = ioutil.ReadAll(r)
|
||||
return b.Put(path, data)
|
||||
}
|
||||
|
||||
func New(db meddler.DB) *Blobstore {
|
||||
return &Blobstore{db}
|
||||
}
|
||||
18
server/blobstore/blobsql/const.go
Normal file
18
server/blobstore/blobsql/const.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package blobsql
|
||||
|
||||
const (
|
||||
tableBlob = "blobs"
|
||||
)
|
||||
|
||||
const (
|
||||
queryBlob = `
|
||||
SELECT *
|
||||
FROM blobs
|
||||
WHERE blob_path = ?;
|
||||
`
|
||||
|
||||
deleteBlob = `
|
||||
DELETE FROM blobs
|
||||
WHERE blob_path = ?;
|
||||
`
|
||||
)
|
||||
11
server/blobstore/blobsql/context.go
Normal file
11
server/blobstore/blobsql/context.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package blobsql
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/context"
|
||||
"github.com/drone/drone/server/blobstore"
|
||||
"github.com/russross/meddler"
|
||||
)
|
||||
|
||||
func NewContext(parent context.Context, db meddler.DB) context.Context {
|
||||
return blobstore.NewContext(parent, New(db))
|
||||
}
|
||||
Reference in New Issue
Block a user