lqs

package module
v0.0.0-...-c0652c3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 4 Imported by: 0

README

LQS (SQL backwards)

This package provides a solution to the issue of setting SQLite PRAGMA statements for each new connection, as discussed in mattn/go-sqlite3 issue #1248.

Background

SQLite drivers like mattn/go-sqlite3 and modernc.org/sqlite support custom PRAGMA statements through URI parameters. However, this approach is not standardized across all drivers. LQS offers a driver-agnostic way to execute PRAGMA statements for each new connection.

Usage

To use LQS, import the package and use the Open function instead of sql.Open:

import (
    "github.com/jtarchie/lqs"
    _ "github.com/mattn/go-sqlite3"
)

func main() {
    db, err := lqs.Open("sqlite3", ":memory:", "PRAGMA cache_size = 1234;")
    if err != nil {
        // Handle error
    }
    defer db.Close()

    // Use db as you would normally
}

The Open function takes three parameters:

  1. The driver name (e.g., "sqlite3")
  2. The data source name (DSN)
  3. SQL statements to be executed for each new connection (e.g., PRAGMA statements)

Testing

The package includes tests to verify that PRAGMA statements are correctly applied to new connections and that errors are properly propagated.

task

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(driverName string, dsn string, preemptive string) (*sql.DB, error)

Open takes the same parameters as `sql.Open` and returns the same values. The extra parameter `preemptive` is SQL statements to be run when a new client is created.

Types

This section is empty.

Jump to

Keyboard shortcuts

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