namespace

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: AGPL-3.0 Imports: 44 Imported by: 0

Documentation

Overview

Define SQL functions that helps to develop plugins

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetQueryType

func GetQueryType(query string) (sqlparser.StatementType, sqlparser.Statement, error)

GetQueryType returns the type of the query (e.g. SELECT, INSERT, SHOW, SET, etc.) Internally, it uses the sqlparser from the vitess project to parse the query and return the type.

If a syntax error is found, it returns an unknown type. Therefore, error will be nil.

func RewriteShowStatement

func RewriteShowStatement(parsedQuery *sqlparser.Show) (string, []interface{})

Take a SHOW statement and return the corresponding SQLite query

Types

type MySQLServer

type MySQLServer struct {
	// The address of the server to bind to
	// (e.g. "localhost:3306")
	Address string

	// Auth file is a path to a file that contains
	// the username and passwords to use for the server
	//
	// It follows the format of the Vitess' file based authentication
	// which can be found at:
	// https://vitess.io/docs/19.0/user-guides/configuration-advanced/static-auth/
	//
	// Note: for safety reasons, the file should be readable only by the user
	// running the server
	AuthFile string

	// A map of users that can be used to authenticate to the server
	//
	// The key is the username and the value is an array of UserEntry.
	// Therefore, a user can have multiple passwords to authenticate
	//
	// If AuthFile is provided, this field will be ignored
	// If neither AuthFile nor Users are provided, the server will accept any connection
	Users map[string][]UserEntry

	// SQLite doesn't use the same exact dialect as MySQL.
	// For example, queries like "SHOW TABLES", "SET", "SHOW DATABASES", "USE"
	// are not supported by SQLite and will return an error.
	//
	// If this field is set to true, the server will catch these MySQL-specific
	// queries and return an adequate answer so that MySQL clients can work with it.
	//
	// Note: this is a best-effort implementation and some queries might not work as expected
	MustCatchMySQLSpecific bool

	// The database connection to SQLite used by the server
	//
	// When the server is closed, the connection will not be closed
	// and it is the responsibility of the caller to close it
	DB *sql.DB

	// The logger used by the server
	Logger *log.Logger
	// contains filtered or unexported fields
}

Represent a MySQL-compatible server to run queries on a sql.DB instance

func (*MySQLServer) Start

func (s *MySQLServer) Start() error

Start the MySQL server

func (*MySQLServer) Stop

func (s *MySQLServer) Stop() error

type Namespace

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

func NewNamespace

func NewNamespace(config NamespaceConfig) (*Namespace, error)

func (*Namespace) GetConnectionString

func (n *Namespace) GetConnectionString() string

func (*Namespace) Init

func (n *Namespace) Init(config NamespaceConfig) error

func (*Namespace) LoadAnyqueryPlugin

func (n *Namespace) LoadAnyqueryPlugin(path string, manifest rpc.PluginManifest, userConfig rpc.PluginConfig, connectionID int) error

Register a plugin written in Go built for anyquery for each table of the manifest

In the manifest, any zeroed string of table name will be ignored

func (*Namespace) LoadAsAnyqueryCLI

func (n *Namespace) LoadAsAnyqueryCLI(path string) error

LoadAsAnyqueryCLI loads the plugins from the configuration of the CLI

It's useful if you want to mimic the behavior of the CLI (internally, the CLI uses this function to load the plugins)

The path is the absolute path to the database used by the CLI. When a plugin can't be loaded, it will be ignored and logged

func (*Namespace) LoadGoPlugin

func (n *Namespace) LoadGoPlugin(plugin sqlite3.Module, name string) error

Load a plugin written in Go

Note: the plugin will only be loaded once the namespace is registered

func (*Namespace) LoadSharedExtension

func (n *Namespace) LoadSharedExtension(path string, entrypoint string) error

Load a SQLite extension built as a shared object (.so)

Note: the plugin will only be loaded once the namespace is registered

func (*Namespace) Register

func (n *Namespace) Register(registerName string) (*sql.DB, error)

Register registers the namespace to the database/sql package

It takes the name of the connection to register. If not specified, a random name will be generated

type NamespaceConfig

type NamespaceConfig struct {
	// If InMemory is set to true, the SQLite database will only be stored in memory
	InMemory bool

	// The path to the SQLite database to open
	//
	// If InMemory is set to true, this field will be ignored
	Path string

	// The connection string to use to connect to the database
	//
	// If set, InMemory and Path will be ignored
	ConnectionString string

	// The page cache size in kilobytes
	//
	// By default, it is set to 50000 KB (50 MB)
	PageCacheSize int

	// Enforce foreign key constraints
	EnforceForeignKeys bool

	// The hclog logger to use from hashicorp/go-hclog
	Logger hclog.Logger

	// If ReadOnly is set to true, the database will be opened in read-only mode
	ReadOnly bool

	// If DevMode is set to true, the namespace will be in development mode
	// Some functions will be available to load and unload plugins
	// This can represent a security risk if the server is exposed to the internet
	// Therefore, it's recommended to disable it in production
	DevMode bool
}

type UserEntry

type UserEntry struct {
	// The clear password of the user used to authenticate
	PasswordClear string

	// The native hashed password of the user used to authenticate
	// (recommended to be used instead of PasswordClear)
	//
	// It is the HEX(sha1(sha1(password))) of the password prefixed by "*"
	PasswordHash string
}

Jump to

Keyboard shortcuts

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