Skip to content

Commit c7b82a1

Browse files
authored
Merge pull request #27 from rqlite/merge-upstream
Merge upstream
2 parents aaa444f + f6c614e commit c7b82a1

File tree

64 files changed

+6105
-2838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6105
-2838
lines changed

.github/workflows/docker.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ jobs:
1717

1818
- name: Run example - simple
1919
run: |
20-
cd ./_example/simple
21-
docker build -t simple .
20+
docker build -t simple -f ./_example/simple/Dockerfile .
2221
docker run simple | grep 99\ こんにちは世界099

_example/json/json.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"database/sql/driver"
6+
"encoding/json"
7+
"fmt"
8+
_ "github.com/mattn/go-sqlite3"
9+
"log"
10+
"os"
11+
)
12+
13+
type Tag struct {
14+
Name string `json:"name"`
15+
Country string `json:"country"`
16+
}
17+
18+
func (t *Tag) Scan(value interface{}) error {
19+
return json.Unmarshal([]byte(value.(string)), t)
20+
}
21+
22+
func (t *Tag) Value() (driver.Value, error) {
23+
b, err := json.Marshal(t)
24+
return string(b), err
25+
}
26+
27+
func main() {
28+
os.Remove("./foo.db")
29+
30+
db, err := sql.Open("sqlite3", "./foo.db")
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
defer db.Close()
35+
36+
_, err = db.Exec(`create table foo (tag jsonb)`)
37+
if err != nil {
38+
log.Fatal(err)
39+
}
40+
41+
stmt, err := db.Prepare("insert into foo(tag) values(?)")
42+
if err != nil {
43+
log.Fatal(err)
44+
}
45+
defer stmt.Close()
46+
_, err = stmt.Exec(`{"name": "mattn", "country": "japan"}`)
47+
if err != nil {
48+
log.Fatal(err)
49+
}
50+
_, err = stmt.Exec(`{"name": "michael", "country": "usa"}`)
51+
if err != nil {
52+
log.Fatal(err)
53+
}
54+
55+
var country string
56+
err = db.QueryRow("select tag->>'country' from foo where tag->>'name' = 'mattn'").Scan(&country)
57+
if err != nil {
58+
log.Fatal(err)
59+
}
60+
fmt.Println(country)
61+
62+
var tag Tag
63+
err = db.QueryRow("select tag from foo where tag->>'name' = 'mattn'").Scan(&tag)
64+
if err != nil {
65+
log.Fatal(err)
66+
}
67+
68+
fmt.Println(tag.Name)
69+
70+
tag.Country = "日本"
71+
_, err = db.Exec(`update foo set tag = ? where tag->>'name' == 'mattn'`, &tag)
72+
if err != nil {
73+
log.Fatal(err)
74+
}
75+
76+
err = db.QueryRow("select tag->>'country' from foo where tag->>'name' = 'mattn'").Scan(&country)
77+
if err != nil {
78+
log.Fatal(err)
79+
}
80+
fmt.Println(country)
81+
}

_example/limit/limit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/mattn/go-sqlite3"
1111
)
1212

13-
func createBulkInsertQuery(n int, start int) (query string, args []interface{}) {
13+
func createBulkInsertQuery(n int, start int) (query string, args []any) {
1414
values := make([]string, n)
15-
args = make([]interface{}, n*2)
15+
args = make([]any, n*2)
1616
pos := 0
1717
for i := 0; i < n; i++ {
1818
values[i] = "(?, ?)"
@@ -27,7 +27,7 @@ func createBulkInsertQuery(n int, start int) (query string, args []interface{})
2727
return
2828
}
2929

30-
func bulkInsert(db *sql.DB, query string, args []interface{}) (err error) {
30+
func bulkInsert(db *sql.DB, query string, args []any) (err error) {
3131
stmt, err := db.Prepare(query)
3232
if err != nil {
3333
return

_example/simple/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# -----------------------------------------------------------------------------
1010
# Build Stage
1111
# -----------------------------------------------------------------------------
12-
FROM golang:alpine AS build
12+
FROM golang:alpine3.18 AS build
1313

1414
# Important:
1515
# Because this is a CGO enabled package, you are required to set it as 1.
@@ -26,7 +26,9 @@ WORKDIR /workspace
2626
COPY . /workspace/
2727

2828
RUN \
29+
cd _example/simple && \
2930
go mod init github.com/mattn/sample && \
31+
go mod edit -replace=github.com/mattn/go-sqlite3=../.. && \
3032
go mod tidy && \
3133
go install -ldflags='-s -w -extldflags "-static"' ./simple.go
3234

_example/vtable/vtable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (vc *ghRepoCursor) Column(c *sqlite3.SQLiteContext, col int) error {
9393
return nil
9494
}
9595

96-
func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
96+
func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []any) error {
9797
vc.index = 0
9898
return nil
9999
}

_example/vtable_eponymous_only/vtable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (vc *seriesCursor) Column(c *sqlite3.SQLiteContext, col int) error {
7777
return nil
7878
}
7979

80-
func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
80+
func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []any) error {
8181
switch {
8282
case len(vals) < 1:
8383
vc.seriesTable.start = 0

backup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3

callback.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ func preUpdateHookTrampoline(handle unsafe.Pointer, dbHandle uintptr, op int, db
100100
// Use handles to avoid passing Go pointers to C.
101101
type handleVal struct {
102102
db *SQLiteConn
103-
val interface{}
103+
val any
104104
}
105105

106106
var handleLock sync.Mutex
107107
var handleVals = make(map[unsafe.Pointer]handleVal)
108108

109-
func newHandle(db *SQLiteConn, v interface{}) unsafe.Pointer {
109+
func newHandle(db *SQLiteConn, v any) unsafe.Pointer {
110110
handleLock.Lock()
111111
defer handleLock.Unlock()
112112
val := handleVal{db: db, val: v}
@@ -124,7 +124,7 @@ func lookupHandleVal(handle unsafe.Pointer) handleVal {
124124
return handleVals[handle]
125125
}
126126

127-
func lookupHandle(handle unsafe.Pointer) interface{} {
127+
func lookupHandle(handle unsafe.Pointer) any {
128128
return lookupHandleVal(handle).val
129129
}
130130

@@ -238,7 +238,7 @@ func callbackArg(typ reflect.Type) (callbackArgConverter, error) {
238238
switch typ.Kind() {
239239
case reflect.Interface:
240240
if typ.NumMethod() != 0 {
241-
return nil, errors.New("the only supported interface type is interface{}")
241+
return nil, errors.New("the only supported interface type is any")
242242
}
243243
return callbackArgGeneric, nil
244244
case reflect.Slice:
@@ -360,11 +360,11 @@ func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error {
360360
}
361361

362362
cb, err := callbackRet(v.Elem().Type())
363-
if err != nil {
364-
return err
365-
}
363+
if err != nil {
364+
return err
365+
}
366366

367-
return cb(ctx, v.Elem())
367+
return cb(ctx, v.Elem())
368368
}
369369

370370
func callbackRet(typ reflect.Type) (callbackRetConverter, error) {

callback_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3
@@ -53,7 +54,7 @@ func TestCallbackArgCast(t *testing.T) {
5354

5455
func TestCallbackConverters(t *testing.T) {
5556
tests := []struct {
56-
v interface{}
57+
v any
5758
err bool
5859
}{
5960
// Unfortunately, we can't tell which converter was returned,
@@ -104,7 +105,7 @@ func TestCallbackConverters(t *testing.T) {
104105
}
105106

106107
func TestCallbackReturnAny(t *testing.T) {
107-
udf := func() interface{} {
108+
udf := func() any {
108109
return 1
109110
}
110111

convert.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var errNilPtr = errors.New("destination pointer is nil") // embedded in descript
2323
// convertAssign copies to dest the value in src, converting it if possible.
2424
// An error is returned if the copy would result in loss of information.
2525
// dest should be a pointer type.
26-
func convertAssign(dest, src interface{}) error {
26+
func convertAssign(dest, src any) error {
2727
// Common cases, without reflect.
2828
switch s := src.(type) {
2929
case string:
@@ -55,7 +55,7 @@ func convertAssign(dest, src interface{}) error {
5555
}
5656
*d = string(s)
5757
return nil
58-
case *interface{}:
58+
case *any:
5959
if d == nil {
6060
return errNilPtr
6161
}
@@ -97,7 +97,7 @@ func convertAssign(dest, src interface{}) error {
9797
}
9898
case nil:
9999
switch d := dest.(type) {
100-
case *interface{}:
100+
case *any:
101101
if d == nil {
102102
return errNilPtr
103103
}
@@ -149,7 +149,7 @@ func convertAssign(dest, src interface{}) error {
149149
*d = bv.(bool)
150150
}
151151
return err
152-
case *interface{}:
152+
case *any:
153153
*d = src
154154
return nil
155155
}
@@ -256,7 +256,7 @@ func cloneBytes(b []byte) []byte {
256256
return c
257257
}
258258

259-
func asString(src interface{}) string {
259+
func asString(src any) string {
260260
switch v := src.(type) {
261261
case string:
262262
return v

0 commit comments

Comments
 (0)