gorqlite

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 6 Imported by: 0

README

This is not used

This is implementation of RQLite but using the RQLite golang client (gorqlite) package. There are some limitation on this because it cannot get schema or status. Since it came with limitation we implement rqlite manually using the API way. That is in rqlite folder implementation.

Documentation

Index

Constants

View Source
const (
	PREFIX_SURESQL_TABLE = "_"
	PREFIX_SQLITE_TABLE  = "sqlite_"
)

Variables

This section is empty.

Functions

func ConditionToParameterized

func ConditionToParameterized(tableName string, c *orm.Condition) (gorqlite.ParameterizedStatement, error)

func DBRecordToInsertParameterized

func DBRecordToInsertParameterized(d *orm.DBRecord) gorqlite.ParameterizedStatement

Convert DBRecord to ParameterizedStatement

func DBRecordsToInsertParameterized

func DBRecordsToInsertParameterized(d orm.DBRecords) []gorqlite.ParameterizedStatement

Convert DBRecords to []ParameterizedStatement

func FromManyParameterizedSQL

func FromManyParameterizedSQL(p []orm.ParametereizedSQL) []gorqlite.ParameterizedStatement

convert from many simpleORM ParameterizedSQL to gorqlite.ParameterizedStatement

func FromOneParameterizedSQL

func FromOneParameterizedSQL(p orm.ParametereizedSQL) gorqlite.ParameterizedStatement

convert from 1 simpleORM ParameterizedSQL to gorqlite.ParameterizedStatement

func WriteResultToBasicSQLResult

func WriteResultToBasicSQLResult(res gorqlite.WriteResult) orm.BasicSQLResult

func WriteResultsToBasicSQLResults

func WriteResultsToBasicSQLResults(res []gorqlite.WriteResult) []orm.BasicSQLResult

Types

type RQLiteDB

type RQLiteDB struct {
	Config RqliteConfig
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(config RqliteConfig) (RQLiteDB, error)

This is to "connect" to the DB. Basically we use gorqlite to do so. If using credential, then it will use that as well and return error if it's not matched

func (RQLiteDB) ExecManySQL

func (db RQLiteDB) ExecManySQL(sql []string) ([]orm.BasicSQLResult, error)

Execute many raw sql statement, can be anything. Query, Update, Insert, etc

func (RQLiteDB) ExecManySQLParameterized

func (db RQLiteDB) ExecManySQLParameterized(p []orm.ParametereizedSQL) ([]orm.BasicSQLResult, error)

Execute many raw sql statement, can be anything. Query, Update, Insert, etc

func (RQLiteDB) ExecOneSQL

func (db RQLiteDB) ExecOneSQL(sql string) orm.BasicSQLResult

Execute 1 raw sql statement, can be anything. Query, Update, Insert, etc Combine the error from write function to result.Err

func (RQLiteDB) ExecOneSQLParameterized

func (db RQLiteDB) ExecOneSQLParameterized(p orm.ParametereizedSQL) orm.BasicSQLResult

Execute 1 raw sql statement, can be anything. Query, Update, Insert, etc

func (RQLiteDB) GetSchema

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

Get all the schema for the database, basically returns all the table that exists!

func (RQLiteDB) InsertManyDBRecords

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

Insert many records, that can be of different tables, that means we have to execute per statement When queue=true the query result is not used, it will return only 1 result with LastInsertID = sequence number and RowsAffected as len(records)

func (RQLiteDB) InsertManyDBRecordsSameTable

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

Insert array of records which we know for sure it's the same table. This should be faster than using InsertManyDBRecords if bulk inserting 1 table with many records When queue=true the query result is not used, instead the first array of Result{LastInsertID : is the sequence number }

func (RQLiteDB) InsertManyTableStructs

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

Insert many table structs (in array) but use the DB records.

func (RQLiteDB) InsertOneDBRecord

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

Insert DBRecord into the DB. The table name is stored in DBRecord if queue == true, this means we are using the queueFunction and there is no error (most of the time) because queueFunction is returning the API status from rqlite, if it succeed it's not the sql command but the API is succeed. if false then we can get the error right away from the command

func (RQLiteDB) InsertOneTableStruct

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

NOTE: with inserting struct, be careful on the ID field. Usually we have

ID in a table with autoincrement, this struct when converted to map
if the struct.ID is not set, it will be converted to the map[ID]=0
So the insert will fail! Use this accordingly!! Saver to use
InsertOneDBRecord() function because we can NOT set the map[ID] to any
value, then the DB will use the default or autoincrement value!

Insert TableStruct to DB

func (RQLiteDB) IsConnected

func (db RQLiteDB) IsConnected() bool

func (RQLiteDB) Leader

func (db RQLiteDB) Leader() (string, error)

Get the leader

func (RQLiteDB) Peers

func (db RQLiteDB) Peers() ([]string, error)

func (RQLiteDB) SelectMany

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

func (RQLiteDB) SelectManyWithCondition

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

Select many rows (returned as []DBRecords) with condition.

func (RQLiteDB) SelectOne

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

NOTE: This is almost not used because very rare cases where we need to select from table without - conditions but only return 1 Select only 1 row, if multiple rows returned, it only takes the first one

func (RQLiteDB) SelectOneWithCondition

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

Select 1 row from a table passed in tableName with condition (read condition struct for usage) Will return only 1 row of type DBRecord and error if any.

func (RQLiteDB) Status

func (db RQLiteDB) Status() (orm.NodeStatusStruct, error)

Returns the status of the database, for Rqlite this will also return the peers and leaders Can use this as ping-pong as well

type RqliteConfig

type RqliteConfig struct {
	URL         string
	Consistency string
	Database    string // actually need to be combined into URL
	Username    string // actually need to be combined into URL
	Password    string // actually need to be combined into URL
	Port        string // actually need to be combined into URL
}

Jump to

Keyboard shortcuts

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