mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Data layer restructuring (#997)
* Move query builders to sqlite package * Add transaction system * Wrap model resolvers in transaction * Add error return value for StringSliceToIntSlice * Update/refactor mutation resolvers * Convert query builders * Remove unused join types * Add stash id unit tests * Use WAL journal mode
This commit is contained in:
@@ -1,74 +1,34 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type GalleryReader interface {
|
||||
// Find(id int) (*Gallery, error)
|
||||
Find(id int) (*Gallery, error)
|
||||
FindMany(ids []int) ([]*Gallery, error)
|
||||
FindByChecksum(checksum string) (*Gallery, error)
|
||||
FindByPath(path string) (*Gallery, error)
|
||||
FindBySceneID(sceneID int) (*Gallery, error)
|
||||
FindByImageID(imageID int) ([]*Gallery, error)
|
||||
// ValidGalleriesForScenePath(scenePath string) ([]*Gallery, error)
|
||||
// Count() (int, error)
|
||||
ValidGalleriesForScenePath(scenePath string) ([]*Gallery, error)
|
||||
Count() (int, error)
|
||||
All() ([]*Gallery, error)
|
||||
// Query(galleryFilter *GalleryFilterType, findFilter *FindFilterType) ([]*Gallery, int)
|
||||
Query(galleryFilter *GalleryFilterType, findFilter *FindFilterType) ([]*Gallery, int, error)
|
||||
GetPerformerIDs(galleryID int) ([]int, error)
|
||||
GetTagIDs(galleryID int) ([]int, error)
|
||||
GetImageIDs(galleryID int) ([]int, error)
|
||||
}
|
||||
|
||||
type GalleryWriter interface {
|
||||
Create(newGallery Gallery) (*Gallery, error)
|
||||
Update(updatedGallery Gallery) (*Gallery, error)
|
||||
// Destroy(id int) error
|
||||
// ClearGalleryId(sceneID int) error
|
||||
UpdatePartial(updatedGallery GalleryPartial) (*Gallery, error)
|
||||
UpdateFileModTime(id int, modTime NullSQLiteTimestamp) error
|
||||
Destroy(id int) error
|
||||
ClearGalleryId(sceneID int) error
|
||||
UpdatePerformers(galleryID int, performerIDs []int) error
|
||||
UpdateTags(galleryID int, tagIDs []int) error
|
||||
UpdateImages(galleryID int, imageIDs []int) error
|
||||
}
|
||||
|
||||
type GalleryReaderWriter interface {
|
||||
GalleryReader
|
||||
GalleryWriter
|
||||
}
|
||||
|
||||
func NewGalleryReaderWriter(tx *sqlx.Tx) GalleryReaderWriter {
|
||||
return &galleryReaderWriter{
|
||||
tx: tx,
|
||||
qb: NewGalleryQueryBuilder(),
|
||||
}
|
||||
}
|
||||
|
||||
type galleryReaderWriter struct {
|
||||
tx *sqlx.Tx
|
||||
qb GalleryQueryBuilder
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) FindMany(ids []int) ([]*Gallery, error) {
|
||||
return t.qb.FindMany(ids)
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) FindByChecksum(checksum string) (*Gallery, error) {
|
||||
return t.qb.FindByChecksum(checksum, t.tx)
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) All() ([]*Gallery, error) {
|
||||
return t.qb.All()
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) FindByPath(path string) (*Gallery, error) {
|
||||
return t.qb.FindByPath(path)
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) FindBySceneID(sceneID int) (*Gallery, error) {
|
||||
return t.qb.FindBySceneID(sceneID, t.tx)
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) FindByImageID(imageID int) ([]*Gallery, error) {
|
||||
return t.qb.FindByImageID(imageID, t.tx)
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) Create(newGallery Gallery) (*Gallery, error) {
|
||||
return t.qb.Create(newGallery, t.tx)
|
||||
}
|
||||
|
||||
func (t *galleryReaderWriter) Update(updatedGallery Gallery) (*Gallery, error) {
|
||||
return t.qb.Update(updatedGallery, t.tx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user