github.com/glebarez/go-sqlite@v1.21.1/README.md (about)

     1  [![Tests](https://github.com/glebarez/go-sqlite/actions/workflows/tests.yml/badge.svg)](https://github.com/glebarez/go-sqlite/actions/workflows/tests.yml)
     2  ![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/glebarez/0fd7561eb29baf31d5362ffee1ae1702/raw/badge-sqlite-version-with-date.json)
     3  
     4  # go-sqlite
     5  This is a pure-Go SQLite driver for Golang's native [database/sql](https://pkg.go.dev/database/sql) package.
     6  The driver has [Go-based implementation of SQLite](https://gitlab.com/cznic/sqlite) embedded in itself (so, you don't need to install SQLite separately)
     7  
     8  # Usage
     9  
    10  ## Example
    11  
    12  ```go
    13  package main
    14  
    15  import (
    16  	"database/sql"
    17  	"log"
    18  
    19  	_ "github.com/glebarez/go-sqlite"
    20  )
    21  
    22  func main() {
    23  	// connect
    24  	db, err := sql.Open("sqlite", ":memory:")
    25  	if err != nil {
    26  		log.Fatal(err)
    27  	}
    28  
    29  	// get SQLite version
    30  	_ := db.QueryRow("select sqlite_version()")
    31  }
    32  ```
    33  
    34  ## Connection string examples
    35  - in-memory SQLite: ```":memory:"```
    36  - on-disk SQLite: ```"path/to/some.db"```
    37  - Foreign-key constraint activation: ```":memory:?_pragma=foreign_keys(1)"```
    38  
    39  ## Settings PRAGMAs in connection string
    40  Any SQLIte pragma can be preset for a Database connection using ```_pragma``` query parameter. Examples:
    41  - [journal mode](https://www.sqlite.org/pragma.html#pragma_journal_mode): ```path/to/some.db?_pragma=journal_mode(WAL)```
    42  - [busy timeout](https://www.sqlite.org/pragma.html#pragma_busy_timeout): ```:memory:?_pragma=busy_timeout(5000)```
    43  
    44  Multiple PRAGMAs can be specified, e.g.:<br>
    45  ```path/to/some.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)```