File: README.md

package info (click to toggle)
golang-github-zombiezen-go-sqlite 1.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: makefile: 3
file content (96 lines) | stat: -rw-r--r-- 3,079 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# `zombiezen.com/go/sqlite`

[![Go Reference](https://pkg.go.dev/badge/zombiezen.com/go/sqlite.svg)][reference docs]

This package provides a low-level Go interface to [SQLite 3][].
It is a fork of [`crawshaw.io/sqlite`][] that uses [`modernc.org/sqlite`][],
a CGo-free SQLite package.
It aims to be a mostly drop-in replacement for `crawshaw.io/sqlite`.

This package deliberately does not provide a `database/sql` driver.
See [David Crawshaw's rationale][] for an in-depth explanation.
If you want to use `database/sql` with SQLite without CGo,
use `modernc.org/sqlite` directly.

[`crawshaw.io/sqlite`]: https://github.com/crawshaw/sqlite
[David Crawshaw's rationale]: https://crawshaw.io/blog/go-and-sqlite
[`modernc.org/sqlite`]: https://pkg.go.dev/modernc.org/sqlite
[reference docs]: https://pkg.go.dev/zombiezen.com/go/sqlite
[SQLite 3]: https://sqlite.org/

## Features

- Full SQLite functionality via `modernc.org/sqlite`,
  an automatically generated translation of the original C source code of SQLite into Go
- Builds with `CGO_ENABLED=0`,
  allowing cross-compiling and data race detection
- Allows access to SQLite-specific features
  like [blob I/O][] and [user-defined functions][]
- Includes a simple [schema migration package][]
- Utilities for [running embedded SQL scripts][ExecScriptFS] using the
  [Go 1.16 embedding feature][]
- A [`go fix`-like tool][migration docs] for migrating existing code using
  `crawshaw.io/sqlite`
- A [simple REPL][] for debugging

[blob I/O]: https://pkg.go.dev/zombiezen.com/go/sqlite#Blob
[ExecScriptFS]: https://pkg.go.dev/zombiezen.com/go/sqlite/sqlitex#ExecScriptFS
[Go 1.16 embedding feature]: https://pkg.go.dev/embed
[migration docs]: cmd/zombiezen-sqlite-migrate/README.md
[schema migration package]: https://pkg.go.dev/zombiezen.com/go/sqlite/sqlitemigration
[simple REPL]: https://pkg.go.dev/zombiezen.com/go/sqlite/shell
[user-defined functions]: https://pkg.go.dev/zombiezen.com/go/sqlite#Conn.CreateFunction

## Install

```shell
go get zombiezen.com/go/sqlite
```

While this library does not use CGo,
make sure that you are building for one of the [supported architectures][].

[supported architectures]: https://pkg.go.dev/modernc.org/sqlite#hdr-Supported_platforms_and_architectures

## Getting Started

```go
import (
  "fmt"

  "zombiezen.com/go/sqlite"
  "zombiezen.com/go/sqlite/sqlitex"
)

// ...

// Open an in-memory database.
conn, err := sqlite.OpenConn(":memory:", sqlite.OpenReadWrite)
if err != nil {
  return err
}
defer conn.Close()

// Execute a query.
err = sqlitex.ExecuteTransient(conn, "SELECT 'hello, world';", &sqlitex.ExecOptions{
  ResultFunc: func(stmt *sqlite.Stmt) error {
    fmt.Println(stmt.ColumnText(0))
    return nil
  },
})
if err != nil {
  return err
}
```

If you're creating a new application,
see the [package examples][] or the [reference docs][].

If you're looking to switch existing code that uses `crawshaw.io/sqlite`,
take a look at the [migration docs][].

[package examples]: https://pkg.go.dev/zombiezen.com/go/sqlite#pkg-examples

## License

[ISC](LICENSE)