Documentation
¶
Index ¶
- Constants
- type NewStoreOptions
- type Record
- func (o *Record) Contents() string
- func (o *Record) CreatedAt() string
- func (o *Record) DeletedAt() string
- func (o *Record) Extension() string
- func (o *Record) GetCreatedAtCarbon() *carbon.Carbon
- func (o *Record) GetDeletedAtCarbon() *carbon.Carbon
- func (o *Record) GetUpdatedAtCarbon() *carbon.Carbon
- func (o *Record) ID() string
- func (o *Record) IsDirectory() bool
- func (o *Record) IsFile() bool
- func (o *Record) IsSoftDeleted() bool
- func (o *Record) Name() string
- func (o *Record) ParentID() string
- func (o *Record) Path() string
- func (o *Record) SetContents(fileContents string) *Record
- func (o *Record) SetCreatedAt(createdAt string) *Record
- func (o *Record) SetDeletedAt(deletedAt string) *Record
- func (o *Record) SetExtension(extension string) *Record
- func (o *Record) SetID(id string) *Record
- func (o *Record) SetName(name string) *Record
- func (o *Record) SetParentID(parentID string) *Record
- func (o *Record) SetPath(filePath string) *Record
- func (o *Record) SetSize(fileSize string) *Record
- func (o *Record) SetType(fileType string) *Record
- func (o *Record) SetUpdatedAt(updatedAt string) *Record
- func (o *Record) Size() string
- func (o *Record) Type() string
- func (o *Record) UpdatedAt() string
- type RecordQueryOptions
- type Store
- func (st *Store) EnableDebug(debug bool)
- func (store *Store) MigrateDown(ctx context.Context, tx ...*sql.Tx) error
- func (store *Store) MigrateUp(ctx context.Context, tx ...*sql.Tx) error
- func (st *Store) RecordCount(ctx context.Context, options RecordQueryOptions) (int64, error)
- func (store *Store) RecordCreate(ctx context.Context, record *Record) error
- func (store *Store) RecordDelete(ctx context.Context, record *Record) error
- func (store *Store) RecordDeleteByID(ctx context.Context, id string) error
- func (store *Store) RecordFindByID(ctx context.Context, id string, options RecordQueryOptions) (*Record, error)
- func (store *Store) RecordFindByPath(ctx context.Context, path string, options RecordQueryOptions) (*Record, error)
- func (store *Store) RecordList(ctx context.Context, options RecordQueryOptions) ([]Record, error)
- func (store *Store) RecordRecalculatePath(ctx context.Context, record *Record, parentRecord *Record) error
- func (store *Store) RecordSoftDelete(ctx context.Context, record *Record) error
- func (store *Store) RecordSoftDeleteByID(ctx context.Context, id string) error
- func (store *Store) RecordUpdate(ctx context.Context, record *Record) error
Constants ¶
const ( COLUMN_ID = "id" COLUMN_PARENT_ID = "parent_id" COLUMN_NAME = "name" COLUMN_PATH = "path" COLUMN_TYPE = "type" COLUMN_SIZE = "size" COLUMN_EXTENSION = "extension" COLUMN_CONTENTS = "contents" COLUMN_CREATED_AT = "created_at" COLUMN_UPDATED_AT = "updated_at" COLUMN_SOFT_DELETED_AT = "soft_deleted_at" )
Database column names used in the file records table.
const MAX_DATETIME = "9999-12-31 23:59:59"
MAX_DATETIME is a far-future datetime used as the default soft-delete sentinel.
const PATH_SEPARATOR = "/"
PATH_SEPARATOR is the path delimiter used throughout the file store.
const ROOT_ID = "0"
ROOT_ID is the ID of the root directory record.
const ROOT_PATH = PATH_SEPARATOR
ROOT_PATH is the path of the root directory.
const TYPE_DIRECTORY = "directory"
TYPE_DIRECTORY is the record type value for directories.
const TYPE_FILE = "file"
TYPE_FILE is the record type value for files.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NewStoreOptions ¶
type NewStoreOptions struct {
TableName string
DB *sql.DB
AutomigrateEnabled bool
DebugEnabled bool
}
NewStoreOptions defines the configuration options for creating a new Store.
type Record ¶
type Record struct {
orm.ShortID
ParentIDField string `db:"parent_id"`
NameField string `db:"name"`
PathField string `db:"path"`
TypeField string `db:"type"`
SizeField string `db:"size"`
ExtensionField string `db:"extension"`
ContentsField string `db:"contents"`
CreatedAtField orm.CreatedAt
UpdatedAtField orm.UpdatedAt
soft_delete.SoftDeletesMaxDate
}
Record represents a file or directory entry in the hierarchical file store.
func NewDirectory ¶
func NewDirectory() *Record
NewDirectory creates a new Record preconfigured as a directory.
func NewRecordFromExistingData ¶
NewRecordFromExistingData creates a Record from a map of existing data.
func (*Record) GetCreatedAtCarbon ¶ added in v1.5.0
GetCreatedAtCarbon returns the created at time as a carbon object.
func (*Record) GetDeletedAtCarbon ¶ added in v1.5.0
GetDeletedAtCarbon returns the soft deleted at time as a carbon object.
func (*Record) GetUpdatedAtCarbon ¶ added in v1.5.0
GetUpdatedAtCarbon returns the updated at time as a carbon object.
func (*Record) IsDirectory ¶
IsDirectory returns true if this record represents a directory.
func (*Record) IsSoftDeleted ¶ added in v1.5.0
IsSoftDeleted returns true if the record is soft deleted.
func (*Record) SetContents ¶
SetContents sets the contents of the record.
func (*Record) SetCreatedAt ¶
SetCreatedAt sets the created at time of the record.
func (*Record) SetDeletedAt ¶
SetDeletedAt sets the soft deleted at time of the record.
func (*Record) SetExtension ¶
SetExtension sets the extension of the record.
func (*Record) SetParentID ¶
SetParentID sets the parent id of the record.
func (*Record) SetPath ¶
SetPath sets the file path. As all paths must start with "/" adds a "/" if not present. Any trailing spaces is also trimmed
func (*Record) SetUpdatedAt ¶
SetUpdatedAt sets the updated at time of the record.
type RecordQueryOptions ¶
type RecordQueryOptions struct {
ID string
IDIn []string
ParentID string
Type string
Path string
PathStartsWith string
CreatedAtLessThan string
CreatedAtGreaterThan string
UpdatedAtLessThan string
UpdatedAtGreaterThan string
Columns []string
Offset int
Limit int
SortOrder string
OrderBy string
CountOnly bool
WithSoftDeleted bool
}
RecordQueryOptions defines the available filters and options for record queries.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides a hierarchical file-system-like storage in a SQL database.
func NewStore ¶
func NewStore(opts NewStoreOptions) (*Store, error)
NewStore creates a new file store instance with the provided options.
func (*Store) EnableDebug ¶
EnableDebug enables or disables SQL debug logging.
func (*Store) MigrateDown ¶ added in v1.4.0
MigrateDown drops the sqlfilestore table
func (*Store) MigrateUp ¶ added in v1.4.0
MigrateUp creates the database table if it doesn't exist and ensures a root directory record is present.
func (*Store) RecordCount ¶
RecordCount returns the count of records matching the provided query options.
func (*Store) RecordCreate ¶
RecordCreate inserts a new record into the database.
func (*Store) RecordDelete ¶
RecordDelete permanently removes a record from the database.
func (*Store) RecordDeleteByID ¶
RecordDeleteByID permanently deletes a record by its ID.
func (*Store) RecordFindByID ¶
func (store *Store) RecordFindByID(ctx context.Context, id string, options RecordQueryOptions) (*Record, error)
RecordFindByID finds a single record by its ID.
func (*Store) RecordFindByPath ¶
func (store *Store) RecordFindByPath(ctx context.Context, path string, options RecordQueryOptions) (*Record, error)
RecordFindByPath finds a single record by its path.
func (*Store) RecordList ¶
RecordList retrieves a list of records matching the provided query options.
func (*Store) RecordRecalculatePath ¶
func (store *Store) RecordRecalculatePath(ctx context.Context, record *Record, parentRecord *Record) error
RecordRecalculatePath updates the path of a record and all its children after a rename or move operation.
func (*Store) RecordSoftDelete ¶
RecordSoftDelete marks a record as deleted by setting the deleted_at timestamp.
func (*Store) RecordSoftDeleteByID ¶
RecordSoftDeleteByID finds a record by ID and marks it as soft deleted.