sqlite3

package
v0.0.0-...-bf49d33 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 13 Imported by: 3

Documentation

Overview

Package sqlite3 provides a zdb driver for SQLite.

This uses https://github.com/mattn/go-sqlite3/

Several connection parameters are set to different defaults in SQLite:

_journal_mode=wal          Almost always faster with better concurrency,
                           with little drawbacks for most use cases.
                           https://www.sqlite.org/wal.html

_foreign_keys=on           Check FK constraints; by default they're not
                           enforced, which is probably not what you want.

_busy_timeout=200          Wait 200ms for locks instead of immediately
                           throwing an error.

_defer_foreign_keys=on     Delay FK checks until the transaction commit; by
                           default they're checked immediately (if
                           enabled).

_case_sensitive_like=on    LIKE is case-sensitive, like PostgreSQL.

_cache_size=-20000         20M cache size, instead of 2M. Can be a
                           significant performance improvement.

You can still use "?_journal_mode=something_else" in the connection string to set something different.

To use a ConnectHook, you can DefaultHook() to automatically set the given connection hook on every new connection. Alternatively, you can register it first using the regular method:

sql.Register("sqlite3-hook1", &sqlite3.SQLiteDriver{
    ConnectHook: func(c *sqlite3.SQLiteConn) error {
        return c.RegisterFunc("hook1", func() string { return "hook1" }, true)
    },
})

And then call zdb.Connect() with "sqlite3-hook1" as the driver name. Note the driver name *must* start with "sqlite3".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHook

func DefaultHook(f func(*sqlite3.SQLiteConn) error)

DefaultHook sets the default SQLite connection hook to use on every connection if no specific hook was specified.

Note that connections made before this are not modified.

Types

This section is empty.

Jump to

Keyboard shortcuts

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