microdb

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Unlicense Imports: 14 Imported by: 1

Documentation

Overview

Package microdb includes all application level components used either with MicroDB client or with in MicroDB system.

Package microdb includes all application level components used either with MicroDB client or with in MicroDB system.

Package microdb includes all application level components used either with MicroDB client or with in MicroDB system.

Package microdb includes all application level components used either with MicroDB client or with in MicroDB system.

Index

Constants

View Source
const (
	// DataOriginTypeMySQL represents a MySQL-based data origin.
	DataOriginTypeMySQL = "mysql"
	// DataOriginTypeSQLite3 represents a SQLite3-based data origin.
	DataOriginTypeSQLite3 = "sqlite3"
)

Variables

This section is empty.

Functions

func AddDataOrigin

func AddDataOrigin(table string, opt DataOriginOption) error

AddDataOrigin adds a new data origin.

func AddDataOriginFromCfg added in v0.1.2

func AddDataOriginFromCfg(name string) error

AddDataOriginFromCfg parses a config file and registers the data origins.

func InsertQuery

func InsertQuery(table string) (string, error)

InsertQuery returns the insert query (sqlite3) for a given table.

func LocalTableQuery

func LocalTableQuery(table string) (string, error)

LocalTableQuery returns the create table query (sqlite3) for a given table.

func NATSConn

func NATSConn(host, port, clusterID, clientID string, sOpts []stan.Option, nOpts []nats.Option) (stan.Conn, error)

NATSConn creates a NATS connection.

func NATSConnFromEnv

func NATSConnFromEnv() (stan.Conn, error)

NATSConnFromEnv create a NATS connection from environment variables.

func OriginTableQuery

func OriginTableQuery(table string) (string, error)

OriginTableQuery returns the create table query (origin) for a given table.

Types

type ConnectionCfg added in v0.1.2

type ConnectionCfg struct {
	OriginType DataOriginType `yaml:"type"`
	Dsn        string         `yaml:"dsn"`
}

ConnectionCfg represents all the info for connecting to the data origin.

type DataOrigin

type DataOrigin struct {
	Schema     *Schema        `yaml:"schema"`
	Connection *ConnectionCfg `yaml:"connection"`
	// contains filtered or unexported fields
}

DataOrigin represents a table in MicroDB. For details, please refers to documentation.

func GetDataOrigin

func GetDataOrigin(table string) (*DataOrigin, error)

GetDataOrigin retreives a DataOrigin given the table name.

func (*DataOrigin) GetDB

func (d *DataOrigin) GetDB() (*sql.DB, error)

GetDB returns a database connection to a specific data origin.

func (*DataOrigin) ReadTopic added in v0.1.1

func (d *DataOrigin) ReadTopic() string

ReadTopic returns the NATS topic name for subscribe to a table's updates.

func (*DataOrigin) WriteTopic added in v0.1.1

func (d *DataOrigin) WriteTopic() string

WriteTopic returns the NATS topic name for table writes.

type DataOriginCfg added in v0.1.2

type DataOriginCfg struct {
	Origins map[string]*DataOrigin `yaml:",inline"`
}

DataOriginCfg represents a config file with all the data origins.

type DataOriginOption

type DataOriginOption func() (*DataOrigin, error)

DataOriginOption represents options for creating a DataOrigin. This is used with AddDataOrigin().

func WithMySQLDataOrigin

func WithMySQLDataOrigin(host, port, user, password, database string, opt SchemaOption) DataOriginOption

WithMySQLDataOrigin creates options for using a new MySQL-based data origin.

type DataOriginType

type DataOriginType string

DataOriginType represents a data origin database type.

type Schema

type Schema struct {
	Table            string `yaml:"table"`
	OriginTableQuery string `yaml:"origin_table_query"`
	LocalTableQuery  string `yaml:"local_table_query,omitempty"`
	InsertQuery      string `yaml:"insert_query,omitempty"`
}

Schema represents the SQL schema for a table.

type SchemaOption added in v0.1.1

type SchemaOption func() (*Schema, error)

SchemaOption represents options for creating a Schema.

func WithSchemaBuilder added in v0.1.1

func WithSchemaBuilder(
	originType DataOriginType,
	table string,
	originTableBuilder *sqlbuilder.CreateTableBuilder,
	originTableStruct *sqlbuilder.Struct,
) SchemaOption

WithSchemaBuilder creates option for a new schema using sqlbuilder.

func WithSchemaStrings added in v0.1.1

func WithSchemaStrings(
	table string,
	originType DataOriginType,
	originTableQuery,
	localTableQuery,
	localInsertQuery string) SchemaOption

WithSchemaStrings creates option for a new schema using raw query strings.

Jump to

Keyboard shortcuts

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