Skip to content

Commit 0a569c3

Browse files
committed
sqinn
1 parent dbbd1ca commit 0a569c3

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
1010

1111
Sqinn-Go is a Go (Golang) library for accessing SQLite databases without cgo.
12-
It uses Sqinn2 <https://github.com/cvilsmeier/sqinn2> under the hood.
13-
It starts Sqinn2 as a child process (`os/exec`) and communicates with
14-
Sqinn2 over stdin/stdout/stderr. The Sqinn2 child process then does the SQLite
12+
It uses Sqinn <https://github.com/cvilsmeier/sqinn> under the hood.
13+
It starts Sqinn as a child process (`os/exec`) and communicates with
14+
Sqinn over stdin/stdout/stderr. The Sqinn child process then does the SQLite
1515
work.
1616

1717
If you want SQLite but do not want cgo, Sqinn-Go can be a solution.
@@ -76,16 +76,16 @@ For usage examples, see `examples` directory.
7676
Building
7777
------------------------------------------------------------------------------
7878

79-
The library uses a pre-built embedded build of sqinn2 for Linux/amd64 and
79+
The library uses a pre-built embedded build of sqinn for Linux/amd64 and
8080
Windows/amd64.
8181

82-
If you do not want to use a pre-built sqinn2 binary, you can compile sqinn2
83-
yourself. See <https://github.com/cvilsmeier/sqinn2> for instructions.
84-
You must then specify the path to sqinn2 like so:
82+
If you do not want to use a pre-built sqinn binary, you can compile sqinn
83+
yourself. See <https://github.com/cvilsmeier/sqinn> for instructions.
84+
You must then specify the path to sqinn like so:
8585

8686
```go
8787
sq := sqinn.MustLaunch(sqinn.Options{
88-
Sqinn2: "/path/to/sqinn2",
88+
Sqinn: "/path/to/sqinn",
8989
})
9090
```
9191

@@ -201,7 +201,7 @@ Changelog
201201
### v2.0.0
202202

203203
- Major Version 2 (less memory, faster)
204-
- Uses sqinn2
204+
- Uses sqinn
205205

206206

207207
### v1.2.0 (2023-10-05)
2 MB
Binary file not shown.
Binary file not shown.

sqinn.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Package sqinn provides interface to SQLite databases in Go without cgo.
3-
It uses Sqinn2 (https://github.com/cvilsmeier/sqinn2) for accessing SQLite
3+
It uses Sqinn (https://github.com/cvilsmeier/sqinn) for accessing SQLite
44
databases. It is not a database/sql driver.
55
*/
66
package sqinn
@@ -23,11 +23,17 @@ import (
2323

2424
// Options for launching a sqinn instance.
2525
type Options struct {
26-
// Path to sqinn2 executable. Can be an absolute or relative path.
26+
// Path to sqinn executable. Can be an absolute or relative path.
2727
// The name ":prebuilt:" is a special name that uses an embedded prebuilt
28-
// sqinn2 binary for linux/amd64 and windows/amd64.
28+
// sqinn binary for linux/amd64 and windows/amd64.
2929
// Default is ":prebuilt:".
30-
Sqinn2 string
30+
Sqinn string
31+
32+
// The database filename. It can be a file system path, e.g. "/tmp/test.db",
33+
// or a special name like ":memory:".
34+
// For further details, see https://www.sqlite.org/c3ref/open.html.
35+
// Default is ":memory:".
36+
Db string
3137

3238
// The loglevel. Can be 0 (off), 1 (info) or 2 (debug).
3339
// Default is 0 (off).
@@ -42,17 +48,11 @@ type Options struct {
4248
// Log can be nil, then nothing will be logged
4349
// Default is nil.
4450
Log func(msg string)
45-
46-
// The database filename. It can be a file system path, e.g. "/tmp/test.db",
47-
// or a special name like ":memory:".
48-
// For further details, see https://www.sqlite.org/c3ref/open.html.
49-
// Default is ":memory:".
50-
Db string
5151
}
5252

5353
// Prebuilt is a special path that tells sqinn-go to use an embedded
54-
// pre-built sqinn2 binary. If Prebuilt is chosen, sqinn-go
55-
// will extract sqinn2 into a temp directory and execute that.
54+
// pre-built sqinn binary. If Prebuilt is chosen, sqinn-go
55+
// will extract sqinn into a temp directory and execute that.
5656
// Not all os/arch combinations are embedded, though.
5757
// Currently we have linux/amd64 and windows/amd64.
5858
const Prebuilt = ":prebuilt:"
@@ -66,34 +66,34 @@ type Sqinn struct {
6666
r *reader
6767
}
6868

69-
//go:embed "prebuilt/linux/sqinn2"
69+
//go:embed "prebuilt/linux/sqinn"
7070
var prebuiltLinux []byte
7171

72-
//go:embed "prebuilt/windows/sqinn2.exe"
72+
//go:embed "prebuilt/windows/sqinn.exe"
7373
var prebuiltWindows []byte
7474

75-
// Launch launches a new sqinn2 subprocess. The [Options] specify
76-
// the sqinn2 executable, the database name, and logging options.
75+
// Launch launches a new sqinn subprocess. The [Options] specify
76+
// the sqinn executable, the database name, and logging options.
7777
// See [Options] for details.
7878
// If an error occurs, it returns (nil, err).
7979
func Launch(opt Options) (*Sqinn, error) {
80-
if opt.Sqinn2 == "" {
81-
opt.Sqinn2 = Prebuilt
80+
if opt.Sqinn == "" {
81+
opt.Sqinn = Prebuilt
8282
}
8383
var tempname string
84-
if opt.Sqinn2 == Prebuilt {
84+
if opt.Sqinn == Prebuilt {
8585
prebuiltMap := map[string][]byte{
8686
"linux/amd64": prebuiltLinux,
8787
"windows/amd64": prebuiltWindows,
8888
}
8989
filenameMap := map[string]string{
90-
"linux": "sqinn2",
91-
"windows": "sqinn2.exe",
90+
"linux": "sqinn",
91+
"windows": "sqinn.exe",
9292
}
9393
platform := runtime.GOOS + "/" + runtime.GOARCH
9494
prebuilt, prebuiltFound := prebuiltMap[platform]
9595
if !prebuiltFound {
96-
return nil, fmt.Errorf("no embedded prebuilt sqinn2 binary found for %s, please see https://github.com/cvilsmeier/sqinn2 for build instructions", platform)
96+
return nil, fmt.Errorf("no embedded prebuilt sqinn binary found for %s, please see https://github.com/cvilsmeier/sqinn for build instructions", platform)
9797
}
9898
tempdir, err := os.MkdirTemp("", "")
9999
if err != nil {
@@ -103,9 +103,13 @@ func Launch(opt Options) (*Sqinn, error) {
103103
if err := os.WriteFile(tempname, prebuilt, 0755); err != nil {
104104
return nil, err
105105
}
106-
opt.Sqinn2 = tempname
106+
opt.Sqinn = tempname
107107
}
108108
var cmdArgs []string
109+
cmdArgs = append(cmdArgs, "run")
110+
if opt.Db != "" {
111+
cmdArgs = append(cmdArgs, "-db", opt.Db)
112+
}
109113
if opt.Loglevel > 0 {
110114
cmdArgs = append(cmdArgs, "-loglevel", strconv.Itoa(opt.Loglevel))
111115
}
@@ -115,11 +119,7 @@ func Launch(opt Options) (*Sqinn, error) {
115119
if opt.Log != nil {
116120
cmdArgs = append(cmdArgs, "-logstderr")
117121
}
118-
if opt.Db != "" {
119-
cmdArgs = append(cmdArgs, "-db", opt.Db)
120-
}
121-
cmdArgs = append(cmdArgs, "-run")
122-
cmd := exec.Command(opt.Sqinn2, cmdArgs...)
122+
cmd := exec.Command(opt.Sqinn, cmdArgs...)
123123
stdinPipe, err := cmd.StdinPipe()
124124
if err != nil {
125125
return nil, err
@@ -140,7 +140,7 @@ func Launch(opt Options) (*Sqinn, error) {
140140
go func() {
141141
sca := bufio.NewScanner(stderrPipe)
142142
for sca.Scan() {
143-
opt.Log("[sqinn2] " + sca.Text())
143+
opt.Log("[sqinn] " + sca.Text())
144144
}
145145
if err := sca.Err(); err != nil {
146146
opt.Log(fmt.Sprintf("cannot read sqinn stderr: %s", err))

sqinn_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010

1111
func TestSqinn(t *testing.T) {
1212
opt := Options{
13-
Sqinn2: Prebuilt,
13+
Sqinn: Prebuilt,
1414
Loglevel: 0,
15-
Log: func(msg string) { t.Logf("SQINN2: %s", msg) },
15+
Log: func(msg string) { t.Logf("SQINN: %s", msg) },
1616
}
1717
sq := MustLaunch(opt)
1818
t.Cleanup(func() {
@@ -234,7 +234,7 @@ func TestSqinn(t *testing.T) {
234234

235235
func TestSqinnLog(t *testing.T) {
236236
opt := Options{
237-
Sqinn2: "", // prebuilt
237+
Sqinn: "", // prebuilt
238238
Loglevel: 0,
239239
Log: func(msg string) { t.Log(msg) },
240240
Db: ":memory:",
@@ -270,7 +270,7 @@ func TestSqinnMust(t *testing.T) {
270270

271271
func TestSqinnBadPath(t *testing.T) {
272272
opt := Options{
273-
Sqinn2: "this_file_does_not_exist",
273+
Sqinn: "this_file_does_not_exist",
274274
Loglevel: 1,
275275
Logfile: "/dev/null",
276276
Db: ":memory:",

0 commit comments

Comments
 (0)