dbfs

package
v0.0.0-...-65fd79d Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TablesDirectory = "tables"
	TablesInfoFile  = "tables.info"
	TableDataFile   = "data"
	TableSchemaFile = "schema"
)

Used filenames.

Variables

This section is empty.

Functions

func Validate

func Validate(fs afero.Fs) error

Validate checks a file system for a valid database file structure. This check is performed in the root directory of the given file system. If an error occurs, it will be returned.

Note: a file structure is also considered invalid, if the contents of certain files do not match. Calling this method will not check every file for its contents, especially no data files. However, it will check for integrity of the tables.info file any will check any indices, if present.

Types

type DBFS

type DBFS struct {
	// contains filtered or unexported fields
}

DBFS represents the structure of a single DataBase-FileSystem. It provides easy access to all folders and files within the root directory, with wrappers for easily modifying the files.

func CreateNew

func CreateNew(fs afero.Fs) (*DBFS, error)

CreateNew initializes a new, empty DBFS in the root of the given file system.

func Load

func Load(fs afero.Fs) (*DBFS, error)

Load loads a DBFS from the given file system.

func (*DBFS) Close

func (dbfs *DBFS) Close() error

Close closes the DBFS and releases all resources.

func (*DBFS) CreateTable

func (dbfs *DBFS) CreateTable(name string) (Table, error)

CreateTable creates empty table files for a table with the given name. This will return an error if a table with the given name already exists. Calling this method will also create an entry in the tables info file.

func (*DBFS) HasTable

func (dbfs *DBFS) HasTable(name string) (bool, error)

HasTable determines whether or not a table with the given name exists in this database.

func (*DBFS) LoadTablesInfo

func (dbfs *DBFS) LoadTablesInfo() (TablesInfo, error)

LoadTablesInfo loads the content of the tables.info file as structured content. The returned TablesInfo is a value, and must be stored using StoreTablesInfo to persist any changes.

func (*DBFS) StoreSchema

func (dbfs *DBFS) StoreSchema(table string, sf *SchemaFile) error

StoreSchema will store the given schema information in the schema file of the table with the given name. If the table doesn't exist, an error is returned. The current content of the schema file will be overwritten.

func (*DBFS) StoreTablesInfo

func (dbfs *DBFS) StoreTablesInfo(info TablesInfo) error

StoreTablesInfo stores the given TablesInfo in the tables.info file. This completely overwrites the existing content in the file.

func (*DBFS) Table

func (dbfs *DBFS) Table(name string) (Table, error)

Table returns a Table object representing the files and directories for the table with the given name, or an error if the table does not exist. Call HasTable to see whether a table with a given name exists.

func (*DBFS) TableCount

func (dbfs *DBFS) TableCount() (int, error)

TableCount returns the amount of tables that currently exist in this database.

type Error

type Error string

Error is a sentinel error type.

const (
	// ErrPageNotExist indicates that the requested page does not exist.
	ErrPageNotExist Error = "page doesn't exist"
)

func (Error) Error

func (e Error) Error() string

type PagedFile

type PagedFile struct {
	// contains filtered or unexported fields
}

PagedFile provides access to pages within a file that is made up of pages. Everything about this file is expensive, and pages and objects of this type should probably be cached whenever possible.

func (*PagedFile) AllocateNewPage

func (pf *PagedFile) AllocateNewPage() (*page.Page, error)

AllocateNewPage will create a new page in this file and immediately write it to disk. The ID of the new page will be determined by calling FindUnusedPageID.

func (*PagedFile) AllocatePageWithID

func (pf *PagedFile) AllocatePageWithID(id page.ID) (*page.Page, error)

AllocatePageWithID will allocate a new page, but instead of finding an available page ID, this will use the given ID. If a page with that ID already exists, an error is returned. Otherwise, the page is added to the PagedFile and a full page is allocated on disk.

func (*PagedFile) Close

func (pf *PagedFile) Close() error

Close will close the underlying file.

func (*PagedFile) FindUnusedPageID

func (pf *PagedFile) FindUnusedPageID() (page.ID, error)

FindUnusedPageID finds an unused page ID in this paged file. You can use this together with AllocatePageWithID, or use AllocateNewPage in the first place.

func (*PagedFile) LoadPage

func (pf *PagedFile) LoadPage(id page.ID) (*page.Page, error)

LoadPage loads a page with the given ID from the disk. If no such page exists, an error is returned. The returned page is an in-memory copy of the page on disk, and modifying will not change any data on the disk. To modify disk data, modify the page and call StorePage with the modified page.

func (*PagedFile) PageCount

func (pf *PagedFile) PageCount() int

PageCount returns the amount of pages that exist in this file.

func (*PagedFile) Pages

func (pf *PagedFile) Pages() []page.ID

Pages returns a slice of page IDs that are present in this paged file. The returned slice is not sorted.

func (*PagedFile) StorePage

func (pf *PagedFile) StorePage(p *page.Page) error

StorePage stores the contents of the page at the offset associated with the page.ID. If there is no offset associated with the page.ID, an error will be returned.

type SchemaFile

type SchemaFile struct {
	HighestRowID int
	Columns      []table.Col
}

SchemaFile provides access to the schema of a table. After modification, call Store to write the modified schema back to disk.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a wrapper around the table directory of a specific table.

func (Table) DataFile

func (t Table) DataFile() (*PagedFile, error)

DataFile returns the data file of the table that this object represents. Calling this will load a new PagedFile, which is expensive. Cache the returned page if possible.

func (Table) SchemaFile

func (t Table) SchemaFile() (*SchemaFile, error)

SchemaFile returns a new schema file which contains information about the table schema.

type TablesInfo

type TablesInfo struct {
	Tables map[string]string `yaml:"tables"`
	Count  int               `yaml:"count"`
}

TablesInfo is a structured representation of the contents in the tables.info file.

Jump to

Keyboard shortcuts

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