schema

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package schema is the schema of the file indexer: its tables, its queries, and the types which are read from, and written to, them.

The schema needs SQLite's full-text search, of fts5, such as:

import _ "github.com/mutablelogic/go-sqlite/ncruces/fts5"

Index

Constants

View Source
const (
	// Version is the version of the schema, of the database's user_version
	Version = 3

	// MinPathLength is the fewest characters of a part of a path, a folder
	// or a name, which is searched
	MinPathLength = 3

	// ListLimit is the most objects which are listed, or searched, at once
	ListLimit = 100

	// DefaultCutoff is the lowest rank of a search, between 0 and 1, unless
	// it's set, so the objects which match it least aren't returned
	DefaultCutoff = 0.15
)

Variables

View Source
var Objects string
View Source
var Queries string

Functions

func Create

func Create(ctx context.Context, conn sqlite.Conn) error

Create creates the schema, in a transaction, when the database hasn't one, and sets its version. A database whose schema is newer is an error.

func FormatSize

func FormatSize(size int64) string

FormatSize returns a size in bytes, or in KiB, MiB, GiB or TiB, with one decimal place, when it's larger

func NewQueries

func NewQueries() (*sqlite.Queries, error)

NewQueries returns the queries, which a connection is bound to, with WithQueries, so the types' selectors and writers use them

Types

type Artwork

type Artwork []byte

Artwork is an object's image, which is read on its own

func (*Artwork) Scan

func (a *Artwork) Scan(row sqlite.Row) error

Scan reads an object's artwork

type ArtworkID

type ArtworkID int64

ArtworkID selects an object's artwork, by its id, which is ErrNotFound when it hasn't any

func (ArtworkID) Select

func (id ArtworkID) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select an object's artwork, by its id

type IndexVolumeRequest

type IndexVolumeRequest struct {
	Path      string `json:"path"`
	Recursive bool   `json:"recursive,omitempty"`
	Reindex   bool   `json:"reindex,omitempty"`
}

IndexVolumeRequest indexes a volume, of a folder, and its folders, when it's recursive, of the files which are new, or changed, or all of them, when they're reindexed

type Object

type Object struct {
	ID      int64          `json:"id"`
	Volume  int64          `json:"volume"`
	Path    string         `json:"path"` // Relative to its volume's
	Size    int64          `json:"size"`
	ModTime time.Time      `json:"modtime"`
	Type    string         `json:"type,omitempty"`
	Kind    string         `json:"kind,omitempty"`
	Title   string         `json:"title,omitempty"`
	Meta    map[string]any `json:"meta,omitempty"`
	Indexed time.Time      `json:"indexed"`        // When it was indexed
	Run     int64          `json:"run"`            // The run of its volume which last saw it
	Rank    *float64       `json:"rank,omitempty"` // How well it matches a search, between 0 and 1, which is higher the better, or nil
}

Object is a file which is indexed, of a volume, which is read

func (Object) Cell

func (o Object) Cell(col int) tui.CellText

Cell returns the column of an object

func (Object) Header

func (o Object) Header() []string

Header returns the columns of an object, as a table's row

func (*Object) Scan

func (o *Object) Scan(row sqlite.Row) error

Scan reads an object

func (Object) String

func (o Object) String() string

func (Object) Width

func (o Object) Width(int) int

Width returns the width of a column, which is its own

type ObjectID

type ObjectID int64

ObjectID selects an object, by its id, to get or delete it

func (ObjectID) Select

func (id ObjectID) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select an object, by its id, to get or delete it

type ObjectList

type ObjectList struct {
	ObjectListRequest
	Count uint64   `json:"count"`
	Body  []Object `json:"body,omitempty"`
}

ObjectList is a list of objects, of its request, with the limit which was used, and their count, without their offset and limit

func (*ObjectList) Scan

func (l *ObjectList) Scan(row sqlite.Row) error

Scan reads an object of a list

func (*ObjectList) ScanCount

func (l *ObjectList) ScanCount(row sqlite.Row) error

ScanCount reads the count of a list

func (ObjectList) String

func (o ObjectList) String() string

type ObjectListRequest

type ObjectListRequest struct {
	sqlite.OffsetLimit
	Volumes []int64  `json:"volume,omitempty" help:"Objects of the volumes, or of all of them"`
	Types   []string `` /* 177-byte string literal not displayed */
	Query   *string  `json:"q,omitempty" help:"Words, which are all in the objects' text"`
	Order   Order    `` /* 163-byte string literal not displayed */
	Cutoff  *float64 `` /* 133-byte string literal not displayed */
}

ObjectListRequest lists objects, of the volumes, or all of them, when there are none, the newest first, or, when there's a query, searches them, of its words, which are all in their text, as prefixes, the best first, unless it has another order. A query without any words matches nothing.

func (*ObjectListRequest) Select

func (r *ObjectListRequest) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select objects, of the volumes, or all of them, which match the query, when there is one

type ObjectMark

type ObjectMark struct {
	Volume  int64
	Path    string
	Size    int64
	ModTime time.Time
	Run     int64
}

ObjectMark selects an object which is as it was, of its volume, path, size and when it was modified, to mark it as seen by its volume's run, rather than indexing it again, with Update, which is ErrNotFound when it isn't

func (ObjectMark) Select

func (m ObjectMark) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select an object which is as it was, to mark it as seen by the run

type ObjectMeta

type ObjectMeta struct {
	Volume  int64          `json:"volume"`          // Its volume
	Path    string         `json:"path"`            // Relative to its volume's
	Size    int64          `json:"size"`            // In bytes
	ModTime time.Time      `json:"modtime"`         // When it was modified
	Type    string         `json:"type,omitempty"`  // Its content type
	Kind    string         `json:"kind,omitempty"`  // Its kind, such as photo or book
	Title   string         `json:"title,omitempty"` // Its title
	Meta    map[string]any `json:"meta,omitempty"`  // Its metadata, of "ns:key"
	Artwork []byte         `json:"-"`               // An image, which is kept, and read on its own
	Text    string         `json:"-"`               // Its content, as Markdown, which is searched, and not kept
	Run     int64          `json:"run"`             // The run of its volume which indexed it
}

ObjectMeta is what's indexed of a file, of a volume, which is written

func (ObjectMeta) Insert

func (o ObjectMeta) Insert(bind *sqlite.Bind) (string, error)

Insert binds an object, which replaces one of its path, with its text

func (ObjectMeta) Update

func (o ObjectMeta) Update(*sqlite.Bind) error

Update isn't implemented: an object is replaced, with Insert

type ObjectPath

type ObjectPath string

ObjectPath selects the objects of a path, to list them: of their volume's path, and their own, or their own, or the end of it, after a /, such as a file's name

func (ObjectPath) Select

func (p ObjectPath) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select the objects of a path, of at most ListLimit, which are of their volumes and paths

type ObjectSweep

type ObjectSweep struct {
	Volume int64
	Run    int64
}

ObjectSweep selects the objects of a volume, which its run didn't see, once its run indexed it, to delete them. The run is the volume's latest, so a run which is indexing, or failed, or an older one, sweeps nothing.

func (ObjectSweep) Select

func (s ObjectSweep) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select the objects of a volume, which its run didn't see, to delete them

type Order

type Order string

Order is the order of a list of objects

const (
	OrderRank  Order = "rank"  // The best match first, of a search, which is its default
	OrderDate  Order = "date"  // The newest first, of when they were modified, which is a list's default
	OrderPath  Order = "path"  // By volume, and path
	OrderSize  Order = "size"  // The largest first
	OrderTitle Order = "title" // By title, of any case, and those without one last
)

The orders of a list of objects, which, when they're the same, are of their volumes and paths

type Progress

type Progress struct {
	Volume  int64     `json:"volume"`
	Path    string    `json:"path"`              // The volume's path
	Run     int64     `json:"run"`               // The run which is indexing it
	Started time.Time `json:"started"`           // When the run started
	Reindex bool      `json:"reindex,omitempty"` // All of its files are indexed again, rather than those which are new, or changed
	Current string    `json:"current,omitempty"` // The file which is being indexed, within the volume
	Total   uint64    `json:"total"`             // The files of the volume, which are counted before it's walked
	Files   uint64    `json:"files"`             // The files which were seen
	Indexed uint64    `json:"indexed"`           // Of which were new, or changed, and were indexed
	Marked  uint64    `json:"marked"`            // Of which were as they were, and were marked
	Swept   uint64    `json:"swept"`             // The objects which weren't seen, which were swept, once it's indexed

	// When it finished, or nil while it's indexing
	Finished *time.Time `json:"finished,omitempty"`
}

Progress is how far a run of a volume has indexed it, while it's indexing, or how it did, once it's finished

type Status

type Status string

Status is the status of a volume's indexing

const (
	StatusNew      Status = "new"      // Not indexed yet
	StatusIndexing Status = "indexing" // Its run is indexing it
	StatusIndexed  Status = "indexed"  // Its run indexed it, and what it didn't see can be swept
	StatusFailed   Status = "failed"   // Its run failed, of its error
)

type Volume

type Volume struct {
	ID       int64      `json:"id"`
	Path     string     `json:"path"`
	Status   Status     `json:"status"`
	Run      int64      `json:"run"`                // The run, which marks the objects it sees, or 0
	Started  *time.Time `json:"started,omitempty"`  // When the run started
	Finished *time.Time `json:"finished,omitempty"` // When it finished, or nil while it's indexing
	Error    string     `json:"error,omitempty"`    // Why it failed
	Reader   string     `json:"reader,omitempty"`   // What read it, of the last run which indexed it
	Objects  uint64     `json:"objects"`            // The objects which are indexed
}

Volume is a folder which is indexed, with the status of its indexing

func (Volume) Cell

func (v Volume) Cell(col int) tui.CellText

Cell returns the column of a volume

func (Volume) Header

func (v Volume) Header() []string

Header returns the columns of a volume, as a table's row

func (*Volume) Scan

func (v *Volume) Scan(row sqlite.Row) error

Scan reads a volume

func (Volume) String

func (v Volume) String() string

func (Volume) Width

func (v Volume) Width(int) int

Width returns the width of a column, which is its own

type VolumeFinish

type VolumeFinish struct {
	Run      int64
	Finished time.Time
	Error    error
	Reader   string // What read it, which is kept when it's indexed
}

VolumeFinish finishes its run, which indexed it, or failed, of its error, with Update, which is ErrNotFound when it isn't indexing, or the run isn't its latest, as another started after it

func (VolumeFinish) Insert

func (VolumeFinish) Insert(*sqlite.Bind) (string, error)

Insert isn't implemented: a volume is added, with VolumeMeta

func (VolumeFinish) Update

func (f VolumeFinish) Update(bind *sqlite.Bind) error

Update binds when its run finished, and whether it failed

type VolumeID

type VolumeID int64

VolumeID selects a volume, by its id, to get, start, finish or delete it

func (VolumeID) Select

func (id VolumeID) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select a volume, by its id, to get, start, finish or delete it, of the writer, VolumeStart or VolumeFinish, which is bound before it

type VolumeList

type VolumeList struct {
	VolumeListRequest
	Count uint64   `json:"count"`
	Body  []Volume `json:"body,omitempty"`
}

VolumeList is a list of volumes, of its request, with the limit which was used, and their count

func (*VolumeList) Scan

func (l *VolumeList) Scan(row sqlite.Row) error

Scan reads a volume of a list

func (*VolumeList) ScanCount

func (l *VolumeList) ScanCount(row sqlite.Row) error

ScanCount reads the count of a list

func (VolumeList) String

func (v VolumeList) String() string

type VolumeListRequest

type VolumeListRequest struct {
	sqlite.OffsetLimit
}

VolumeListRequest lists the volumes, by their paths

func (*VolumeListRequest) Select

func (r *VolumeListRequest) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select the volumes, by their paths

type VolumeMeta

type VolumeMeta struct {
	Path string `json:"path"`
}

VolumeMeta is a folder which is indexed, by its absolute path, which is added, or is the one of it already

func (VolumeMeta) Insert

func (v VolumeMeta) Insert(bind *sqlite.Bind) (string, error)

Insert binds a volume, which is added, or is the one of its path already

func (VolumeMeta) Update

func (v VolumeMeta) Update(*sqlite.Bind) error

Update isn't implemented: a volume is of its path

type VolumePath

type VolumePath string

VolumePath selects a volume, by its absolute path, to get it

func (VolumePath) Select

func (p VolumePath) Select(bind *sqlite.Bind, op sqlite.Op) (string, error)

Select a volume, by its path

type VolumeStart

type VolumeStart struct {
	Started time.Time
}

VolumeStart starts its next run, which is indexing it, with Update

func (VolumeStart) Insert

func (VolumeStart) Insert(*sqlite.Bind) (string, error)

Insert isn't implemented: a volume is added, with VolumeMeta

func (VolumeStart) Update

func (s VolumeStart) Update(bind *sqlite.Bind) error

Update binds when its run started

Jump to

Keyboard shortcuts

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