mssql

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Codec:     encoding.JSON,
	Interval:  30 * time.Second,
	TableName: "gokv_test",
	Split:     false,
}

Functions

func Insert

func Insert(engine *xorm.Engine, data interface{}) error

Types

type Item

type Item struct {
	Key       string    `xorm:"varchar(64) not null pk id"`
	Data      string    `xorm:"varchar(256) not null data"`
	ExpiresAt time.Time `xorm:"datetime expiresAt"`
	CTime     time.Time `xorm:"updated ctime"`
	Table     string    `xorm:"-"`
	Split     bool      `xorm:"-"`
}

Item identifes a cached piece of data

func (*Item) IsExpired

func (i *Item) IsExpired() bool

Helper method to check if an item is expired. Current usecase for this is for garbage collection

func (*Item) TableName

func (i *Item) TableName() string

type Options

type Options struct {
	User      string
	Pwd       string
	Host      string
	Db        string
	Codec     encoding.Codec
	Interval  time.Duration
	TableName string
	Split     bool
}

options are the options for the mssql store.

type SqlSvr

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

func (*SqlSvr) Close

func (s *SqlSvr) Close()

type Store

type Store struct {
	Sql   *SqlSvr
	Codec encoding.Codec
}

Store is a gokv.Store implementation for SQL databases.

func New

func New(options Options) *Store

New create a mssql connection.

func (*Store) Close

func (s *Store) Close() error

Close closes the Store. It must be called to return all open connections to the connection pool and to release any open resources.

func (*Store) Delete

func (s *Store) Delete(k string) error

Delete 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 (*Store) GC

func (s *Store) GC()

GC recycle expire items

func (*Store) Get

func (s *Store) Get(k string, v interface{}) (found bool, err 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). The key must not be "" and the pointer must not be nil.

func (*Store) Has

func (s *Store) Has(k string) bool

func (*Store) Set

func (s *Store) Set(k string, v interface{}) 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.

func (*Store) SetEx

func (s *Store) SetEx(k string, v interface{}, expires time.Duration) error

SetEx store the give value for the given key and the key expire after expires.

Jump to

Keyboard shortcuts

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