database

package
v3.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MARKDOWN_BUCKET_NAME = "markdown"
)
View Source
const (
	MARKDOWN_DB_SCHEMA = "" +
		"CREATE TABLE IF NOT EXISTS `markdown` (" +
		"    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT," +
		"    `key` VARCHAR(255) NOT NULL,    " +
		"    `content` TEXT NOT NULL," +
		"    `create_time` DATETIME(3) NOT NULL," +
		"    PRIMARY KEY (`id`), " +
		"    UNIQUE KEY `key` (`key`)" +
		") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
)
View Source
const (
	MARKDOWN_DIR = "markdown"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BboltDB

type BboltDB struct {
}

BboltDB implement Database interface with ETCD's bbolt

func (*BboltDB) Close

func (d *BboltDB) Close() error

Close close the db file

func (*BboltDB) CountAll

func (d *BboltDB) CountAll() (int, error)

CountAll Fetch records count

func (*BboltDB) DeviceTokenByKey

func (d *BboltDB) DeviceTokenByKey(key string) (string, error)

DeviceTokenByKey get device token of specified key

func (*BboltDB) GetMarkdownByKey

func (d *BboltDB) GetMarkdownByKey(key string) (string, error)

Get Markdown Content by key

func (*BboltDB) SaveDeviceTokenByKey

func (d *BboltDB) SaveDeviceTokenByKey(key, deviceToken string) (string, error)

SaveDeviceToken create or update device token of specified key

func (*BboltDB) SaveMarkdown

func (d *BboltDB) SaveMarkdown(content string) (string, error)

Save Markdown Content

type Database

type Database interface {
	CountAll() (int, error)                                 //Get db records count
	DeviceTokenByKey(key string) (string, error)            //Get specified device's token
	SaveDeviceTokenByKey(key, token string) (string, error) //Create or update specified devices's token
	GetMarkdownByKey(key string) (string, error)            // Get Markdown Content by key
	SaveMarkdown(content string) (string, error)            // Save Markdown Content
	Close() error                                           //Close the database
}

Database defines all of the db operation

func NewBboltdb

func NewBboltdb(dataDir string) Database

func NewEnvBase

func NewEnvBase() Database

func NewMySQL

func NewMySQL(dsn string) Database

type EnvBase

type EnvBase struct {
}

func (*EnvBase) Close

func (d *EnvBase) Close() error

func (*EnvBase) CountAll

func (d *EnvBase) CountAll() (int, error)

func (*EnvBase) DeviceTokenByKey

func (d *EnvBase) DeviceTokenByKey(key string) (string, error)

func (*EnvBase) GetMarkdownByKey

func (d *EnvBase) GetMarkdownByKey(key string) (string, error)

Get Markdown Content by key

func (*EnvBase) SaveDeviceTokenByKey

func (d *EnvBase) SaveDeviceTokenByKey(key, token string) (string, error)

func (*EnvBase) SaveMarkdown

func (d *EnvBase) SaveMarkdown(content string) (string, error)

Save Markdown Content

type MySQL

type MySQL struct {
}

func (*MySQL) Close

func (d *MySQL) Close() error

func (*MySQL) CountAll

func (d *MySQL) CountAll() (int, error)

func (*MySQL) DeviceTokenByKey

func (d *MySQL) DeviceTokenByKey(key string) (string, error)

func (*MySQL) GetMarkdownByKey

func (d *MySQL) GetMarkdownByKey(key string) (string, error)

Get Markdown Content by key

func (*MySQL) SaveDeviceTokenByKey

func (d *MySQL) SaveDeviceTokenByKey(key, token string) (string, error)

func (*MySQL) SaveMarkdown

func (d *MySQL) SaveMarkdown(content string) (string, error)

Save Markdown Content

Jump to

Keyboard shortcuts

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