sqlkv

package
v0.0.0-...-45da7de Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 8 Imported by: 1

README

create table kv
(
    k       varchar(100) not null primary key,
    v       text,
    state   tinyint      not null default 1,
    updated datetime,
    created datetime     not null
)

Documentation

Index

Constants

View Source
const (
	DefaultAllSQL    = `select k,v from kv where state = 1`
	DefaultGetSQL    = `select v from kv where k = :k and state = 1`
	DefaultInsertSQL = `insert into kv(k, v, state, created) values(:k, :v, 1, :time)`
	DefaultUpdateSQL = `update kv set v = :v, updated = :time, state = 1 where k = :k`
	DefaultDelSQL    = `update kv set state = 0  where k = :k`
)

Variables

This section is empty.

Functions

func Default

func Default(s, defaultValue string) string

func DefaultDuration

func DefaultDuration(s, defaultValue time.Duration) time.Duration

Types

type Client

type Client struct {
	Config
	// contains filtered or unexported fields
}

Client is a gokv.Store implementation for SQL databases.

func NewClient

func NewClient(c Config) (*Client, error)

func (*Client) All

func (c *Client) All() (kvs map[string]string, er error)

All list the keys in the store.

func (*Client) Del

func (c *Client) Del(k string) (er error)

Del deletes the stored value for the given key. Deleting a non-existing key-value pair does NOT lead to an error. The key must not be "".

func (*Client) Get

func (c *Client) Get(k string) (found bool, v string, er error)

Get retrieves the stored value for the given key. You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil).

func (*Client) Set

func (c *Client) Set(k, v string) (er error)

Set stores the given value for the given key. Values are automatically marshalled to JSON or gob (depending on the configuration). The key must not be "" and the value must not be nil.

type Config

type Config struct {
	DriverName     string
	DataSourceName string

	AllSQL    string
	GetSQL    string
	UpdateSQL string
	InsertSQL string
	DelSQL    string

	// RefreshInterval will Refresh the key values from the database in every Refresh interval.
	RefreshInterval time.Duration
}

Jump to

Keyboard shortcuts

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