common

package
v0.0.0-...-f43442f Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: BSL-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DATA_FILE_NAME = ".store/data.bin"
View Source
const METADATA_FILE_PATH = ".store/metadata.bin"

Variables

View Source
var ColumnsTypeEnum = [3]string{
	"number",
	"string",
	"bool",
}
View Source
var ErrClosedFile error = errors.New("File is closed")
View Source
var ResponseStrings = map[string]string{
	"T1": "Table with this id not found",
	"C1": "This column type is not allowed",
	"C2": "Column with this name was not found",
	"R0": "Row with id %d has been found",
	"R1": "Row with this id was not found",
	"R2": "Row with id %d has been deleted",
	"R3": "New row has been created with id %d",
}

Functions

func Config

func Config(configData DatabaseStore)

func CreateFile

func CreateFile(name string) *os.File

func DecodeJson

func DecodeJson[T IDecodedJson](r *http.Request) (*T, error)

func Dump

func Dump()

func EncodeJson

func EncodeJson[T Row[string] | TableColumn | []Row[string]](obj T) (string, error)

func ReadConfigFile

func ReadConfigFile[T []Table | []TableMetaData](name string) (T, error)

func SyncDBFiles

func SyncDBFiles()

func WriteFile

func WriteFile(file io.Writer, binData any) error

Types

type ColumnIdType

type ColumnIdType uint32

func FindColumnByName

func FindColumnByName(tid TableIdType, name string) (ColumnIdType, error)

type DatabaseStore

type DatabaseStore struct {
	Tables         []Table
	TablesMetaData []TableMetaData
}
var Store DatabaseStore

func Load

func Load() (bool, DatabaseStore)

type DeleteRowType

type DeleteRowType struct {
	Table TableIdType `json:"table"`
	// contains filtered or unexported fields
}

type File

type File struct {
	Path     string
	Desc     *os.File
	Content  []byte
	IsOpened bool
}

func NewFile

func NewFile(path string) File

func (File) Append

func (f File) Append(bytes []byte) error

func (*File) Close

func (f *File) Close()

func (*File) ReadBytes

func (f *File) ReadBytes() ([]byte, error)

func (File) WriteBytes

func (f File) WriteBytes(bytes []byte) error

func (File) WriteString

func (f File) WriteString(content string) error

type FilterType

type FilterType map[string][]string

type GetRow

type GetRow struct {
	Table TableIdType `json:"table"`
	// contains filtered or unexported fields
}

type IDecodedJson

type IDecodedJson interface {
	NewRow | GetRow | NewColumn | UpdateRowData | DeleteRowType
}

type NewColumn

type NewColumn struct {
	Name  string      `json:"name"`
	Table TableIdType `json:"table"`
	Type  string      `json:"type"`
}

type NewRow

type NewRow struct {
	Columns map[string]interface{} `json:"columns"`
	Table   TableIdType            `json:"table"`
}

type Row

type Row[T ColumnIdType | string] struct {
	Id      RowIdType         `json:"id"`
	Columns map[T]interface{} `json:"columns"`
}

func GetRowById

func GetRowById(tid TableIdType, id RowIdType) (Row[ColumnIdType], error)

type RowIdType

type RowIdType uint64

func AddNewRow

func AddNewRow(tid TableIdType, cols map[ColumnIdType]interface{}) (RowIdType, error)

type Table

type Table struct {
	Id   TableIdType
	Rows []Row[ColumnIdType]
}

func (*Table) DeleteRow

func (t *Table) DeleteRow(rid RowIdType) error

func (Table) UpdateRow

func (t Table) UpdateRow(rid RowIdType, diff map[ColumnIdType]interface{}) error

type TableColumn

type TableColumn struct {
	Id         ColumnIdType `json:"id"`
	Name       string       `json:"name"`
	Type       uint8        `json:"type"`
	IsOptional bool         `json:"isoptional"`
}

type TableIdType

type TableIdType uint8

type TableMetaData

type TableMetaData struct {
	Name    string
	Columns []TableColumn
}

func (*TableMetaData) CreateNewColumn

func (table *TableMetaData) CreateNewColumn(name string, colType uint8) (ColumnIdType, error)

type UpdateRowData

type UpdateRowData struct {
	Table   TableIdType            `json:"table"`
	Colunms map[string]interface{} `json:"columns"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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