storage

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: BSD-3-Clause Imports: 3 Imported by: 10

README

storage GoDoc

Usage

local storage = require("storage")

-- storage.open
local s, err = storage.open("./test/db.json")
if err then error(err) end

-- storage:set(): key, value, ttl (default = 60s)
local err = s:set("key", {"one", "two", 1}, 10)
if err then error(err) end

-- storage:get()
local value, found, err = s:get("key")
if err then error(err) end
if not found then error("must be found") end
-- value == {"one", "two", 1}

-- storage:set(): override with set max ttl
local err = s:set("key", "override", nil)
local value, found, err = s:get("key")
if not(value == "override") then error("must be found") end

-- storage:keys()
local list = s:keys()
-- list == {"key"}

-- storage:dump()
local dump, err = s:dump()
if err then error(err) end
-- list == {"key" = "override"}

Documentation

Overview

Package storage implements persist storage with ttl for to save and share data between differents lua.LState.

Example (Package)

storage.open(), storage_ud:get(), storage_ud:set()

state := lua.NewState()
Preload(state)
inspect.Preload(state)
time.Preload(state)
source := `
local storage = require("storage")
local inspect = require("inspect")

local s, err = storage.open("./test/db-example.json")
if err then error(err) end

local err = s:set("key", {"one", "two", 1}, 10)
if err then error(err) end

local value, found, err = s:get("key")
if err then error(err) end
if not found then error("must be found") end

print(inspect(value, {newline="", indent=""}))

local list = s:keys()
print(#list == 1)

local dump, err = s:dump()
if err then error(err) end
print(inspect(dump, {newline="", indent=""}))

os.remove("./test/db-example.json")
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

{ "one", "two", 1 }
true
{key = { "one", "two", 1 }}

Index

Examples

Constants

View Source
const (
	// default driver mode
	DefaultDriver = `memory`
)

Variables

This section is empty.

Functions

func Close

func Close(L *lua.LState) int

Close lua storage_ud:close() return err

func Dump

func Dump(L *lua.LState) int

Dump lua storage_ud:dump() return (table, error)

func Get

func Get(L *lua.LState) int

Get lua storage_ud:set(key) returns (value, bool, err)

func Keys

func Keys(L *lua.LState) int

Keys lua storage_ud:list_keys() return (table, error)

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func New

func New(L *lua.LState) int

New lua storage.new(path, driver) returns (storage_ud, err)

func Preload

func Preload(L *lua.LState)

Preload adds storage to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local storage = require("storage")

func Set

func Set(L *lua.LState) int

Set lua storage_ud:set(key, value, ttl) return err

func Sync

func Sync(L *lua.LState) int

Sync lua storage_ud:sync() return err

Types

This section is empty.

Directories

Path Synopsis
multiple storage engines
multiple storage engines
memory
this storage can be used for projects that do not store much data and do not save memory
this storage can be used for projects that do not store much data and do not save memory

Jump to

Keyboard shortcuts

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