connection.go
connection.go - Overview
-
Overview This file manages the SQLite database connection and initialization for the query service. It sets up the database connection, initializes organization preferences and RBAC groups.
-
Detailed Documentation
type ModelDaoSqlite
- Purpose: Represents the data access object for SQLite.
- Fields:
bundb *bun.DB
: Represents the bun database connection.
func InitDB(sqlStore sqlstore.SQLStore) (*ModelDaoSqlite, error)
- Purpose: Initializes the database connection and performs initial setup tasks, such as initializing organization preferences and RBAC.
- Parameters:
sqlStore sqlstore.SQLStore
: An interface for interacting with the SQL store.
- Returns:
*ModelDaoSqlite
: A pointer to the initialized ModelDaoSqlite struct.error
: An error if initialization fails.
func (mds *ModelDaoSqlite) DB() *bun.DB
- Purpose: Returns the underlying bun database connection.
- Parameters:
mds *ModelDaoSqlite
: The receiver, a pointer to the ModelDaoSqlite struct.
- Returns:
*bun.DB
: The bun database connection.
func (mds *ModelDaoSqlite) initializeOrgPreferences(ctx context.Context) error
- Purpose: Initializes organization preferences, including telemetry settings.
- Parameters:
ctx context.Context
: The context for the operation.
- Returns:
error
: An error if initialization fails.
func (mds *ModelDaoSqlite) initializeRBAC(ctx context.Context) error
- Purpose: Initializes Role-Based Access Control (RBAC) by creating default groups (ADMIN, EDITOR, VIEWER) if they don't exist.
- Parameters:
ctx context.Context
: The context for the operation.
- Returns:
error
: An error if initialization fails.
func (mds *ModelDaoSqlite) createGroupIfNotPresent(ctx context.Context, name string) (*types.Group, error)
- Purpose: Creates a group with the given name if it does not already exist.
- Parameters:
ctx context.Context
: The context for the operation.name string
: The name of the group to create.
- Returns:
*types.Group
: The created or existing group.error
: An error if the operation fails.
Include in Getting Started: NO