litedoc

package module
v0.0.0-...-19d724b Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 10 Imported by: 0

README

litedoc

Document database that uses SQLite as it's storage engine.

Documentation

Overview

Package litedoc provides a document database that uses SQLite as it's storage engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	ID string
	// contains filtered or unexported fields
}

Collection represents the top level structure that holds Documents.

func (*Collection) Document

func (c *Collection) Document(id string) *Document

Document returns a reference to a Document within the Collection.

func (*Collection) Query

func (c *Collection) Query(ctx context.Context, keypath string, op Op, val any) ([]*Document, error)

Query returns a list of Documents where the values at keypath match the value based on the Op used.

func (*Collection) QueryAll

func (c *Collection) QueryAll(ctx context.Context) ([]*Document, error)

type Database

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

Database holds the underlying SQLite database connection.

func Use

func Use(db *sql.DB) (*Database, error)

Use with a SQLite connection.

func (*Database) Close

func (db *Database) Close() error

Close calls Close on the underlying database.

func (*Database) Collection

func (db *Database) Collection(id string) *Collection

Collection returns a reference to a database collection.

func (*Database) Export

func (db *Database) Export(ctx context.Context, dir string) error

Export dumps all of the collection tables to disk.

func (*Database) Import

func (db *Database) Import(ctx context.Context, fsys fs.FS) error

Import loads .json files from the root of the fs.FS provided. Rules:

  1. Each file should be named [COLLECTION_NAME].jsonl
  2. Each file should be JSON objects on each line of the file
  3. Each JSON object should have an "ID" key

type Document

type Document struct {
	ID string
	// contains filtered or unexported fields
}

Document represents a JSON document stored in a Collection.

func (*Document) Create

func (d *Document) Create(ctx context.Context, doc any) error

Create will create a new Document with the doc type within the Collection it references creating the Collection if it does not already exist. The Document is stored as it's JSON encoded format.

func (*Document) DataTo

func (d *Document) DataTo(doc any) error

DataTo unmarshals the JSON data into the doc type if the JSON data exists.

func (*Document) Delete

func (d *Document) Delete(ctx context.Context) error

Delete will remove the Document from the Collection it references.

func (*Document) Get

func (d *Document) Get(ctx context.Context, doc any) error

Get will find a single Document by it's ID and call DataTo for you to decode the JSON into the doc's type.

func (*Document) Set

func (d *Document) Set(ctx context.Context, doc any) error

Set will update a Document with the doc type within the Collection it references creating the Collection if it does not already exist. Set will fail if the Document does not already exist in the database. Create should be used first.

func (*Document) UnmarshalJSON

func (d *Document) UnmarshalJSON(data []byte) error

type Op

type Op int

Op is a comparison operator when querying for documents.

const (
	OpEqual Op = iota
	OpNotEqual
	OpLessThan
	OpLessThanEqual
	OpGreaterThan
	OpGreaterThanEqual
	OpLike
)

func (Op) String

func (op Op) String() string

Jump to

Keyboard shortcuts

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