pathdb

package module
v0.0.0-...-54ee1dd Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

README

This is a Go port of https://github.com/getlantern/db-android.

The internal data model is not completely compatible. Paths in db-android are stored as serde serialized BLOBs (e.g. T/mypath), whereas in pathdb they are stored as strings (e.g. mypath). This was necessary to allow pathdb to work with iOS. The impact is that when we switch Android to use pathdb, we'll have to migrate the data from existing DBs over to a new pathdb and convert paths in the process. This shouldn't be too hard.

Documentation

Index

Constants

View Source
const (
	TEXT           = 'T'
	BYTEARRAY      = 'A'
	BYTE           = '2'
	BOOLEAN        = 'B'
	SHORT          = 'S'
	INT            = 'I'
	LONG           = 'L'
	FLOAT          = 'F'
	DOUBLE         = 'D'
	PROTOCOLBUFFER = 'P'
	JSON           = 'J'
)

Variables

View Source
var (
	ErrUnregisteredProtobufType = errors.New("unregistered protocol buffer type")
	ErrUnregisteredJSONType     = errors.New("unregistered json type")
	ErrUnkownDataType           = errors.New("unknown data type")
)
View Source
var (
	ErrUnexpectedDBError = errors.New("unexpected database error")
)
View Source
var File_pbuf_test_proto protoreflect.FileDescriptor

Functions

func Delete

func Delete(t TX, path string) error

func Get

func Get[T any](q Queryable, path string) (T, error)

func GetOrPut

func GetOrPut[T any](t TX, path string, value T, fullText string) (T, error)

func ListPaths

func ListPaths(q Queryable, query *QueryParams) ([]string, error)

func Mutate

func Mutate(d DB, fn func(TX) error) error

func Put

func Put[T any](t TX, path string, value T, fullText string) error

func PutAll

func PutAll[T any](t TX, values map[string]T) error

func PutIfAbsent

func PutIfAbsent[T any](t TX, path string, value T, fullText string) (bool, error)

func PutRaw

func PutRaw[T any](t TX, path string, value *Raw[T], fullText string) error

func Subscribe

func Subscribe[T any](d DB, sub *Subscription[T]) error

func Unsubscribe

func Unsubscribe(d DB, id string)

Types

type ChangeSet

type ChangeSet[T any] struct {
	Updates map[string]*Item[*Raw[T]]
	Deletes map[string]bool
}

type DB

type DB interface {
	Queryable
	Begin() (TX, error)
	WithSchema(string) DB
	Subscribe(*subscription)
	Unsubscribe(string)
	RegisterType(id int16, example interface{})
}

func NewDB

func NewDB(core minisql.DB, schema string) (DB, error)

type Item

type Item[T any] struct {
	Path       string
	DetailPath string
	Value      T
}

func List

func List[T any](q Queryable, query *QueryParams) ([]*Item[T], error)

func RList

func RList[T any](q Queryable, query *QueryParams) ([]*Item[*Raw[T]], error)

type PBUFObject

type PBUFObject struct {
	A string  `protobuf:"bytes,1,opt,name=a,proto3" json:"a,omitempty"`
	B float64 `protobuf:"fixed64,2,opt,name=b,proto3" json:"b,omitempty"`
	// contains filtered or unexported fields
}

func (*PBUFObject) Descriptor deprecated

func (*PBUFObject) Descriptor() ([]byte, []int)

Deprecated: Use PBUFObject.ProtoReflect.Descriptor instead.

func (*PBUFObject) GetA

func (x *PBUFObject) GetA() string

func (*PBUFObject) GetB

func (x *PBUFObject) GetB() float64

func (*PBUFObject) ProtoMessage

func (*PBUFObject) ProtoMessage()

func (*PBUFObject) ProtoReflect

func (x *PBUFObject) ProtoReflect() protoreflect.Message

func (*PBUFObject) Reset

func (x *PBUFObject) Reset()

func (*PBUFObject) String

func (x *PBUFObject) String() string

type QueryParams

type QueryParams struct {
	Path                string
	Start               int
	Count               int
	ReverseSort         bool
	JoinDetails         bool
	IncludeEmptyDetails bool
}

func (*QueryParams) ApplyDefaults

func (query *QueryParams) ApplyDefaults()

type Queryable

type Queryable interface {
	Get(path string) ([]byte, error)
	List(query *QueryParams, search *SearchParams) ([]*item, error)
	// contains filtered or unexported methods
}

type Raw

type Raw[T any] struct {
	Bytes []byte
	// contains filtered or unexported fields
}

func LoadedRaw

func LoadedRaw[T any](db DB, value T) *Raw[T]

func RGet

func RGet[T any](q Queryable, path string) (*Raw[T], error)

func UnloadedRaw

func UnloadedRaw[T any](db DB, value T) *Raw[T]

func (*Raw[T]) Value

func (r *Raw[T]) Value() (T, error)

func (*Raw[T]) ValueOrProtoBytes

func (r *Raw[T]) ValueOrProtoBytes() (interface{}, error)

type SearchParams

type SearchParams struct {
	Search         string
	HighlightStart string
	HighlightEnd   string
	Ellipses       string
	NumTokens      int
}

func (*SearchParams) ApplyDefaults

func (search *SearchParams) ApplyDefaults()

type SearchResult

type SearchResult[T any] struct {
	Item[T]
	Snippet string
}

func RSearch

func RSearch[T any](q Queryable, query *QueryParams, search *SearchParams) ([]*SearchResult[*Raw[T]], error)
func Search[T any](q Queryable, query *QueryParams, search *SearchParams) ([]*SearchResult[T], error)

type Subscription

type Subscription[T any] struct {
	ID             string
	PathPrefixes   []string
	JoinDetails    bool
	ReceiveInitial bool
	OnUpdate       func(*ChangeSet[T]) error
}

type TX

type TX interface {
	Queryable
	Put(path string, value interface{}, serializedValue []byte, fullText string, updateIfPresent bool) error
	Delete(path string) error
	Commit() error
	Rollback() error
}

Directories

Path Synopsis
Package minisql defines the subset of interfaces from database/sql that's needed to support pathdb.
Package minisql defines the subset of interfaces from database/sql that's needed to support pathdb.

Jump to

Keyboard shortcuts

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