2023-09-13 06:03:25 +02:00
|
|
|
package sqlite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/driver"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage/share"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
driver.RegisterDocumentStoreFactory("sqlite", documentStoreFactory)
|
|
|
|
driver.RegisterBlobStoreFactory("sqlite", blobStoreFactory)
|
|
|
|
driver.RegisterShareStoreFactory("sqlite", shareStoreFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
func documentStoreFactory(url *url.URL) (storage.DocumentStore, error) {
|
|
|
|
dir := filepath.Dir(url.Host + url.Path)
|
|
|
|
|
2023-12-03 14:26:18 +01:00
|
|
|
if dir != "." {
|
2023-09-13 06:03:25 +02:00
|
|
|
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path := url.Host + url.Path + "?" + url.RawQuery
|
|
|
|
|
|
|
|
db, err := Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewDocumentStoreWithDB(db), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func blobStoreFactory(url *url.URL) (storage.BlobStore, error) {
|
|
|
|
dir := filepath.Dir(url.Host + url.Path)
|
|
|
|
|
2023-12-03 14:26:18 +01:00
|
|
|
if dir != "." {
|
2023-09-13 06:03:25 +02:00
|
|
|
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path := url.Host + url.Path + "?" + url.RawQuery
|
|
|
|
|
|
|
|
db, err := Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewBlobStoreWithDB(db), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func shareStoreFactory(url *url.URL) (share.Store, error) {
|
|
|
|
dir := filepath.Dir(url.Host + url.Path)
|
|
|
|
|
2023-12-03 14:26:18 +01:00
|
|
|
if dir != "." {
|
2023-09-13 06:03:25 +02:00
|
|
|
if err := os.MkdirAll(dir, os.FileMode(0750)); err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path := url.Host + url.Path + "?" + url.RawQuery
|
|
|
|
|
|
|
|
db, err := Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewShareStoreWithDB(db), nil
|
|
|
|
}
|