infra

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package infra defines dnote structure

Index

Constants

This section is empty.

Variables

View Source
var (
	// DnoteDirName is the name of the directory containing dnote files
	DnoteDirName = ".dnote"

	// SystemSchema is the key for schema in the system table
	SystemSchema = "schema"
	// SystemRemoteSchema is the key for remote schema in the system table
	SystemRemoteSchema = "remote_schema"
	// SystemLastSyncAt is the timestamp of the server at the last sync
	SystemLastSyncAt = "last_sync_time"
	// SystemLastMaxUSN is the user's max_usn from the server at the alst sync
	SystemLastMaxUSN = "last_max_usn"
	// SystemLastUpgrade is the timestamp at which the system more recently checked for an upgrade
	SystemLastUpgrade = "last_upgrade"
	// SystemCipherKey is the encryption key
	SystemCipherKey = "enc_key"
	// SystemSessionKey is the session key
	SystemSessionKey = "session_token"
	// SystemSessionKeyExpiry is the timestamp at which the session key will expire
	SystemSessionKeyExpiry = "session_token_expiry"
)

Functions

func InitDB added in v0.4.5

func InitDB(ctx DnoteCtx) error

InitDB initializes the database. Ideally this process must be a part of migration sequence. But it is performed seaprately because it is a prerequisite for legacy migration.

Types

type Config

type Config struct {
	Editor string
}

Config holds dnote configuration

type DB added in v0.6.0

type DB struct {
	Conn SQLCommon
}

DB contains information about the current database connection

func OpenDB added in v0.6.0

func OpenDB(dbPath string) (*DB, error)

OpenDB initializes a new connection to the sqlite database

func (*DB) Begin added in v0.6.0

func (d *DB) Begin() (*DB, error)

Begin begins a transaction

func (*DB) Close added in v0.6.0

func (d *DB) Close() error

Close closes a db connection

func (*DB) Commit added in v0.6.0

func (d *DB) Commit() error

Commit commits a transaction

func (*DB) Exec added in v0.6.0

func (d *DB) Exec(query string, values ...interface{}) (sql.Result, error)

Exec executes a sql

func (*DB) Prepare added in v0.6.0

func (d *DB) Prepare(query string) (*sql.Stmt, error)

Prepare prepares a sql

func (*DB) Query added in v0.6.0

func (d *DB) Query(query string, values ...interface{}) (*sql.Rows, error)

Query queries rows

func (*DB) QueryRow added in v0.6.0

func (d *DB) QueryRow(query string, values ...interface{}) *sql.Row

QueryRow queries a row

func (*DB) Rollback added in v0.6.0

func (d *DB) Rollback() error

Rollback rolls back a transaction

type DnoteCtx

type DnoteCtx struct {
	HomeDir          string
	DnoteDir         string
	APIEndpoint      string
	Version          string
	DB               *DB
	SessionKey       string
	SessionKeyExpiry int64
	CipherKey        []byte
}

DnoteCtx is a context holding the information of the current runtime

func NewCtx added in v0.4.5

func NewCtx(apiEndpoint, versionTag string) (DnoteCtx, error)

NewCtx returns a new dnote context

func SetupCtx added in v0.6.0

func SetupCtx(ctx DnoteCtx) (DnoteCtx, error)

SetupCtx populates context and returns a new context

type SQLCommon added in v0.6.0

type SQLCommon interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

SQLCommon is the minimal interface required by a db connection

Jump to

Keyboard shortcuts

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