file

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package file implements storage on the local filesystem, with one file per document.

Index

Constants

View Source
const Name = "file"

Name of the storage.

Variables

This section is empty.

Functions

func Get

func Get() storage.IStorage

Get returns a setup storage, or set it up.

func Set

func Set(s storage.IStorage)

Set sets the storage, primarily used for testing.

Types

type CreateAny

type CreateAny struct {
	// Create directory and file if it does not exist.
	CreateIfNotExist bool `default:"true" json:"create_if_not_exist"`
}

CreateAny is a struct for the `create.Create` `Any` field.

type File

type File struct {
	*storage.Storage

	// Target allows to set a static target. If it is empty, the target will be
	// dynamic - the one set at the operation (count, create, delete, etc) time.
	// Depending on the storage, target is a collection, a table, a bucket, etc.
	// For ElasticSearch, for example it doesn't have a concept of a database -
	// the target then is the index. Due to different cases of ElasticSearch
	// usage, the target can be static or dynamic - defined at the index time,
	// for example: log-{YYYY}-{MM}. For File, it isn't used at all.
	Target string `json:"-" validate:"omitempty,gt=0"`
}

File storage definition.

func New

func New(ctx context.Context) (*File, error)

New creates a new File storage.

func (*File) BulkCreate

func (s *File) BulkCreate(
	ctx context.Context,
	_ string,
	items []storage.BulkItem,
	prm *create.Create,
	options ...storage.Func[*create.Create],
) (storage.BulkResult, error)

BulkCreate creates data in chunks of 25. File has no batch primitive, so each item's ID is used as its file path and written with Create.

func (*File) Close

func (s *File) Close() error

Close releases the resources held by the storage. File opens and closes descriptors per operation, so Close is a no-op.

func (*File) Count

func (s *File) Count(ctx context.Context, target string, prm *count.Count, options ...storage.Func[*count.Count]) (int64, error)

Count returns the number of items in the storage.

func (*File) Create

func (s *File) Create(ctx context.Context, id, target string, v any, prm *create.Create, options ...storage.Func[*create.Create]) (string, error)

Create data.

NOTE: Not all storages returns the ID, neither all storages requires `id` to be set. You are better off setting the ID yourself.

func (*File) Delete

func (s *File) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...storage.Func[*delete.Delete]) error

Delete removes data.

func (*File) GetClient

func (s *File) GetClient() any

GetClient returns the client.

func (*File) List

func (s *File) List(ctx context.Context, target string, v any, prm *list.List, options ...storage.Func[*list.List]) error

List data.

Search is a glob matched against filenames. Sort, Limit, Offset, and Fields are applied to the decoded documents after matching.

func (*File) Retrieve

func (s *File) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, options ...storage.Func[*retrieve.Retrieve]) error

Retrieve data.

func (*File) Update

func (s *File) Update(ctx context.Context, id, target string, v any, prm *update.Update, options ...storage.Func[*update.Update]) error

Update data.

NOTE: Not truly an update, it's an insert.

type ResponseList

type ResponseList[T any] struct {
	Items []T `json:"items"`
}

ResponseList is the list response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址