sqlite

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README


title: 'SQLite'

This connector allows you to connect to SQLite databases. SQLite is a self-contained, serverless, zero-configuration, transactional SQL database engine.

Configuration

The connector supports the following configuration options:

# Simple connection string format
sqlite: "path/to/database.db"

# Or detailed configuration
sqlite:
  hosts: ["/path/to/directory"]  # Directory containing the database file
  database: "database.db"        # Database file name
  read_only: false              # Whether to open database in read-only mode
  memory: false                 # Whether to create an in-memory database

Configuration Options

  • hosts: List of database file paths. If specified with database, the first host is used as the directory path.
  • database: Database file name. If specified with hosts, it's combined with the first host path.
  • read_only: Whether to open the database in read-only mode. Defaults to false.
  • memory: Whether to create an in-memory database. If true, ignores hosts and database settings.
  • conn_string: Direct connection string. If provided, all other options are ignored.

Examples

  1. Using a file-based database:
sqlite:
  hosts: ["/data"]
  database: "mydb.db"
  1. Using an in-memory database:
sqlite:
  memory: true
  1. Using a direct connection string:
sqlite: "/absolute/path/to/database.db"

Features

  • Supports both file-based and in-memory SQLite databases
  • Read-only mode support
  • Named parameter support in queries (using :param syntax)
  • Automatic table discovery
  • Column type inference
  • Transaction support

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Hosts      []string `json:"hosts" yaml:"hosts"`             // List of database file paths
	Database   string   `json:"database" yaml:"database"`       // Database file name
	ReadOnly   bool     `json:"read_only" yaml:"read_only"`     // Whether to open database in read-only mode
	Memory     bool     `json:"memory" yaml:"memory"`           // Whether to create an in-memory database
	ConnString string   `json:"conn_string" yaml:"conn_string"` // Direct connection string
}

Config represents the configuration for a SQLite connection

func (Config) ConnectionString

func (c Config) ConnectionString() string

ConnectionString generates a connection string for SQLite

func (Config) Doc

func (c Config) Doc() string

Doc returns documentation about the configuration

func (Config) ExtraPrompt

func (c Config) ExtraPrompt() []string

ExtraPrompt returns additional prompt information for the configuration

func (Config) Readonly

func (c Config) Readonly() bool

func (Config) Type

func (c Config) Type() string

Type returns the type of the connector

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface

func (Config) Validate

func (c Config) Validate() error

Validate checks if the configuration is valid

type Connector

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

Connector implements the connectors.Connector interface for SQLite

func (Connector) Config

func (c Connector) Config() connectors.Config

func (Connector) Discovery

func (c Connector) Discovery(ctx context.Context, tablesList []string) ([]model.Table, error)

func (*Connector) GuessColumnType

func (c *Connector) GuessColumnType(sqlType string) model.ColumnType

GuessColumnType implements TypeGuesser interface for SQLite

func (*Connector) InferQuery

func (c *Connector) InferQuery(ctx context.Context, query string) ([]model.ColumnSchema, error)

func (Connector) LoadsColumns

func (c Connector) LoadsColumns(ctx context.Context, tableName string) ([]model.ColumnSchema, error)

func (Connector) Ping

func (c Connector) Ping(ctx context.Context) error

func (Connector) Query

func (c Connector) Query(ctx context.Context, endpoint model.Endpoint, params map[string]any) ([]map[string]any, error)

func (Connector) Sample

func (c Connector) Sample(ctx context.Context, table model.Table) ([]map[string]any, error)

Jump to

Keyboard shortcuts

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