goususqlite3

package module
v2.0.0-...-b942c1c Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 8 Imported by: 0

README

SQLite3-Integration for Go Universal Service Utilities

Full docu for go-gousu on https://github.com/indece-official/go-gousu

Usage

Config flags
Flag Env-Var Type Default Description
sqlite3_filename SQLITE3_FILENAME string "db.sqlite" Filename of sqlite database
sqlite3_cache SQLITE3_CACHE string "private" SQLite3 cache mode: shared
sqlite3_mode SQLITE3_MODE string "rwc" SQLite3 access mode: ro
sqlite3_max_retries SQLITE3_MAX_RETRIES int 10 Max number of retries before connecting to db fails
sqlite3_retry_interval SQLITE3_RETRY_INTERVAL int 6 Interval in seconds between retrying to connect to db
sqlite3_max_idle_conns SQLITE3_MAX_IDLE_CONNS int 0 Maximum number of idle connections (0 is unlimited)
sqlite3_max_open_conns SQLITE3_MAX_OPEN_CONNS int 0 Maximum number of open connections (0 is unlimited)

Documentation

Index

Constants

View Source
const ServiceName = "sqlite3"

ServiceName defines the name of sqlite3 service used for dependency injection

Variables

This section is empty.

Functions

This section is empty.

Types

type IService

type IService interface {
	gousu.IService

	GetDB() *sql.DB
	GetDBSafe() (*sql.DB, error)
}

IService defined the interface of the sqlite3 database service

type MockService

type MockService struct {
	gousu.MockService

	GetDBFunc           func() *sql.DB
	GetDBSafeFunc       func() (*sql.DB, error)
	GetDBFuncCalled     int
	GetDBSafeFuncCalled int
}

MockService for simply mocking IService

func NewMockService

func NewMockService() *MockService

NewMockService creates a new initialized instance of MockService

func (*MockService) GetDB

func (s *MockService) GetDB() *sql.DB

GetDB calls GetDBFunc and increases GetDBFuncCalled

func (*MockService) GetDBSafe

func (s *MockService) GetDBSafe() (*sql.DB, error)

GetDBSafe calls GetDBSafeFunc and increases GetDBSafeFuncCalled

type Options

type Options struct {
	// SetupSQL can contain the content of a sql-file for updating the
	// database on startup
	SetupSQL string

	// UpdateSQL can contain the content of a sql-file for updating the
	// database on startup
	UpdateSQL string

	// GetDBRevisionSQL can be used for retrieving the revision of the database
	// used, must return/select one integer field
	GetDBRevisionSQL string

	// OpenFunc can be used to override the default sql.Open
	OpenFunc func(driverName string, dataSourceName string) (*sql.DB, error)
}

Options can contain parameters passed to the sqlite3 service

type Service

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

Service provides the interaction with the sqlite3 database

func NewServiceBase

func NewServiceBase(ctx gousu.IContext, options *Options) *Service

NewServiceBase creates a new instance of sqlite3-service, should be used instead

of generating it manually

func (*Service) GetDB deprecated

func (s *Service) GetDB() *sql.DB

GetDB returns the sqlite3 db connection

Deprecated: Use GetDBSafe() instead

func (*Service) GetDBSafe

func (s *Service) GetDBSafe() (*sql.DB, error)

GetDBSafe returns the sqlite3 db connection after verifying it is alive

func (*Service) Health

func (s *Service) Health() error

Health checks the health of the sqlite3-service by pinging the sqlite3 database

func (*Service) Name

func (s *Service) Name() string

Name returns the name of redis service from ServiceName

func (*Service) Start

func (s *Service) Start() error

Start initializes the connection to the sqlite3 database and executed both setup.sql and update.sql after connecting

func (*Service) Stop

func (s *Service) Stop() error

Stop currently does nothing

Jump to

Keyboard shortcuts

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