rqlite

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PREFIX_SURESQL_TABLE = "_"
	PREFIX_SQLITE_TABLE  = "sqlite_"
	SCHEMA_TABLE         = "sqlite_master"

	// RQLite API endpoints
	ENDPOINT_EXECUTE       = "/db/execute"
	ENDPOINT_QUERY         = "/db/query"
	ENDPOINT_UNIFIED       = "/db/request"
	ENDPOINT_LOAD          = "/db/load"
	ENDPOINT_BACKUP        = "/db/backup" // curl -s -XGET localhost:4001/db/backup -o bak.sqlite3 (returns might need to be saved as a file right away)
	ENDPOINT_BOOT          = "/boot"
	ENDPOINT_SNAPSHOT      = "/snapshot"
	ENDPOINT_STATUS        = "/status" // option are /status?pretty
	ENDPOINT_READY         = "/readyz" // option readyz?noleader or /readyz?sync&timeout=5s
	ENDPOINT_JOIN          = "/join"
	ENDPOINT_REMOVE        = "/remove"
	ENDPOINT_NODE          = "/nodes" // can have nodes?pretty&ver=2 for improved JSON format
	ENDPOINT_DEBUG         = "/debug"
	ENDPOINT_VARS          = "/debug/vars"
	ENDPOINT_PPROF_CMDLINE = "/debug/pprof/cmdline"
	ENDPOINT_PPROF_PROFILE = "/debug/pprof/profile"
	ENDPOINT_PPROF_SYMBOL  = "/debug/pprof/symbol"

	DEFAULT_MAX_POOL = 25

	// Default timeouts
	DEFAULT_TIMEOUT       = 30 * time.Second
	DEFAULT_RETRY_TIMEOUT = 2 * time.Second
	DEFAULT_MAX_RETRIES   = 3
)

Variables

This section is empty.

Functions

func GetStatusInfoFromResponse

func GetStatusInfoFromResponse(raw map[string]interface{}) (orm.NodeStatusStruct, error)

Types

type ExecuteResponse

type ExecuteResponse struct {
	Results []ExecuteResult `json:"results"`
	Time    float64         `json:"time"`
}

ExecuteResponse represents the response from a write operation

type ExecuteResult

type ExecuteResult struct {
	LastInsertID int     `json:"last_insert_id"`
	RowsAffected int     `json:"rows_affected"`
	Time         float64 `json:"time"`
	Error        string  `json:"error,omitempty"`
}

ExecuteResult represents a single result from a write operation

type QueryResponse

type QueryResponse struct {
	Results []QueryResult `json:"results"`
	Time    float64       `json:"time"`
}

QueryResponse represents the response from a read operation

type QueryResult

type QueryResult struct {
	Columns []string        `json:"columns"`
	Types   []string        `json:"types"`
	Values  [][]interface{} `json:"values"`
	Time    float64         `json:"time"`
	Error   string          `json:"error,omitempty"`
}

QueryResult represents a single result from a read operation

type RQLiteDirectDB

type RQLiteDirectDB struct {
	Config     RqliteDirectConfig
	HTTPClient *http.Client
}

RQLiteDirectDB implements the orm.Database interface for direct HTTP access to RQLite

func NewDatabase

func NewDatabase(config RqliteDirectConfig) (*RQLiteDirectDB, error)

NewDatabase creates a new RQLiteDirectDB instance

func (*RQLiteDirectDB) ExecManySQL

func (db *RQLiteDirectDB) ExecManySQL(sqls []string) ([]orm.BasicSQLResult, error)

ExecManySQL executes multiple SQL statements

func (*RQLiteDirectDB) ExecManySQLParameterized

func (db *RQLiteDirectDB) ExecManySQLParameterized(paramSQLs []orm.ParametereizedSQL) ([]orm.BasicSQLResult, error)

ExecManySQLParameterized executes multiple parameterized SQL statements

func (*RQLiteDirectDB) ExecOneSQL

func (db *RQLiteDirectDB) ExecOneSQL(sql string) orm.BasicSQLResult

ExecOneSQL executes a single SQL statement

func (*RQLiteDirectDB) ExecOneSQLParameterized

func (db *RQLiteDirectDB) ExecOneSQLParameterized(paramSQL orm.ParametereizedSQL) orm.BasicSQLResult

ExecOneSQLParameterized executes a single parameterized SQL statement

func (*RQLiteDirectDB) GetSchema

func (db *RQLiteDirectDB) GetSchema(hideSQL, hideSureSQL bool) []orm.SchemaStruct

GetSchema returns the database schema

func (*RQLiteDirectDB) InsertManyDBRecords

func (db *RQLiteDirectDB) InsertManyDBRecords(records []orm.DBRecord, queue bool) ([]orm.BasicSQLResult, error)

InsertManyDBRecords inserts multiple records

func (*RQLiteDirectDB) InsertManyDBRecordsSameTable

func (db *RQLiteDirectDB) InsertManyDBRecordsSameTable(records []orm.DBRecord, queue bool) ([]orm.BasicSQLResult, error)

InsertManyDBRecordsSameTable inserts multiple records into the same table

func (*RQLiteDirectDB) InsertManyTableStructs

func (db *RQLiteDirectDB) InsertManyTableStructs(objs []orm.TableStruct, queue bool) ([]orm.BasicSQLResult, error)

InsertManyTableStructs inserts multiple table structs

func (*RQLiteDirectDB) InsertOneDBRecord

func (db *RQLiteDirectDB) InsertOneDBRecord(record orm.DBRecord, queue bool) orm.BasicSQLResult

InsertOneDBRecord inserts a single record

func (*RQLiteDirectDB) InsertOneTableStruct

func (db *RQLiteDirectDB) InsertOneTableStruct(obj orm.TableStruct, queue bool) orm.BasicSQLResult

InsertOneTableStruct inserts a single table struct

func (*RQLiteDirectDB) IsConnected

func (db *RQLiteDirectDB) IsConnected() bool

IsConnected checks if the database connection is alive

func (*RQLiteDirectDB) Leader

func (db *RQLiteDirectDB) Leader() (string, error)

Leader returns the leader node of the RQLite cluster

func (*RQLiteDirectDB) Peers

func (db *RQLiteDirectDB) Peers() ([]string, error)

Peers returns the peer nodes of the RQLite cluster

func (*RQLiteDirectDB) SelectMany

func (db *RQLiteDirectDB) SelectMany(tableName string) (orm.DBRecords, error)

SelectMany selects multiple records from the table

func (*RQLiteDirectDB) SelectManySQL

func (db *RQLiteDirectDB) SelectManySQL(sqls []string) ([]orm.DBRecords, error)

SelectManySQL executes multiple SQL queries and returns the results of each

func (*RQLiteDirectDB) SelectManySQLParameterized

func (db *RQLiteDirectDB) SelectManySQLParameterized(paramSQLs []orm.ParametereizedSQL) ([]orm.DBRecords, error)

SelectManySQLParameterized executes multiple parameterized SQL queries

func (*RQLiteDirectDB) SelectManyWithCondition

func (db *RQLiteDirectDB) SelectManyWithCondition(tableName string, condition *orm.Condition) ([]orm.DBRecord, error)

SelectManyWithCondition selects multiple records with a condition

func (*RQLiteDirectDB) SelectOne

func (db *RQLiteDirectDB) SelectOne(tableName string) (orm.DBRecord, error)

SelectOne selects a single record from the table

func (*RQLiteDirectDB) SelectOneSQL

func (db *RQLiteDirectDB) SelectOneSQL(sql string) (orm.DBRecords, error)

SelectOneSQL executes a single SQL query and returns the results

func (*RQLiteDirectDB) SelectOneSQLParameterized

func (db *RQLiteDirectDB) SelectOneSQLParameterized(paramSQL orm.ParametereizedSQL) (orm.DBRecords, error)

SelectOneSQLParameterized executes a single parameterized SQL query

func (*RQLiteDirectDB) SelectOneWithCondition

func (db *RQLiteDirectDB) SelectOneWithCondition(tableName string, condition *orm.Condition) (orm.DBRecord, error)

SelectOneWithCondition selects a single record with a condition

func (*RQLiteDirectDB) SelectOnlyOneSQL

func (db *RQLiteDirectDB) SelectOnlyOneSQL(sql string) (orm.DBRecord, error)

SelectOnlyOneSQL executes a SQL query and ensures exactly one row is returned

func (*RQLiteDirectDB) SelectOnlyOneSQLParameterized

func (db *RQLiteDirectDB) SelectOnlyOneSQLParameterized(paramSQL orm.ParametereizedSQL) (orm.DBRecord, error)

SelectOnlyOneSQLParameterized executes a parameterized SQL query and ensures exactly one row is returned

func (*RQLiteDirectDB) Status

func (db *RQLiteDirectDB) Status() (orm.NodeStatusStruct, error)

Status returns the status of the RQLite cluster

type RqliteDirectConfig

type RqliteDirectConfig struct {
	URL         string        // Base URL for the RQLite node (e.g. "http://localhost:4001")
	Consistency string        // Consistency level: "none", "weak", "strong"
	Username    string        // Optional username for authentication
	Password    string        // Optional password for authentication
	Timeout     time.Duration // HTTP client timeout
	RetryCount  int           // Number of retries for failed requests
}

RqliteDirectConfig holds configuration for direct RQLite connections

Jump to

Keyboard shortcuts

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