Skip to content

Commit ca474f9

Browse files
committed
1.16.1
1 parent f7fb4d1 commit ca474f9

File tree

156 files changed

+1206676
-1153423
lines changed

Some content is hidden

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

156 files changed

+1206676
-1153423
lines changed

README.md

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# sqlite
22

3-
一个不使用cgo的database/sql标准sqlite3驱动,原驱动`modernc.org/sqlite`,但是速度不行,在github上边没有,就从gitlab搬迁过来,同时修改了驱动名称为sqlite3,这样不用任何修改,就能在goframe框架中使用.
3+
一个不使用cgo的database/sql标准sqlite3驱动,原驱动`modernc.org/sqlite`,增加对goframe2+框架的支持(最新goframe已经有不使用cgo驱动了).
44

5-
### 非框架使用方法
5+
### 常规使用方法
66
~~~
77
"github.com/jmoiron/sqlx"
88
_ "github.com/logoove/sqlite"
@@ -15,7 +15,7 @@ type User struct {
1515
}
1616
1717
func main() {
18-
db, _ = sqlx.Open("sqlite3", "./db.db")
18+
db, _ = sqlx.Open("sqlite", "./db.db")
1919
db.Exec(`CREATE TABLE users (
2020
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
2121
"name" char(15) NOT NULL
@@ -28,47 +28,18 @@ func main() {
2828
}
2929
~~~
3030

31-
### goframe1.17
32-
33-
配置在config/config.toml
34-
~~~
35-
[database]
36-
type= "sqlite"
37-
link= "./public/resource/db.db"
38-
debug = true
39-
~~~
40-
然后在boot 下面boot.go文件里面加上
41-
~~~
42-
_ "github.com/logoove/sqlite"
43-
~~~
44-
### goframe2.0
31+
### goframe2.0+使用方法
4532
在manifeat/config/config.yaml配置
4633
~~~
4734
# 数据库连接配置
4835
database:
49-
logger:
50-
path: "./temp/logs/sql"
51-
level: "all"
52-
stdout: true
53-
ctxKeys: ["RequestId"]
5436
default:
5537
type: "sqlite"
5638
link: "./resource/db.db" #数据库路径根据自己的填写
5739
debug: true
5840
~~~
59-
在internel/cmd文件夹中放入sqlite.go驱动文件,已经将驱动改成sqlite3,所以能够直接在goframe2.0中使用.驱动文件在examples里面
60-
61-
### 插入数据两个goframe版本一样
62-
~~~
63-
id, _ := g.Model("user").Data(g.Map{"name": "john", "age": 1}).InsertAndGetId()
64-
~~~
65-
66-
### examples是例子
67-
gf17是gf1.7
68-
gflay是gf2.0
69-
sqlx是不使用框架
70-
sqlite.go是gf2.0驱动
7141
### 更新日志
42+
2023-10-09 v1.16.1 修复对goframe支持,更新到gitlab.com/cznic/sqlite最新1.26同步.对于goframe2以下版本可能不能使用.
7243

7344
2022-3-22 v1.15.3 新增win amd64编译,解决内存泄漏问题.
7445

addport.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2022 The Sqlite Authors. All rights reserved
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build ignore
6+
// +build ignore
7+
8+
package main
9+
10+
import (
11+
"fmt"
12+
"os"
13+
"path/filepath"
14+
"strings"
15+
)
16+
17+
func fail(rc int, msg string, args ...interface{}) {
18+
fmt.Fprintf(os.Stderr, msg, args...)
19+
os.Exit(rc)
20+
}
21+
22+
func main() {
23+
if len(os.Args) != 3 {
24+
fail(1, "expected 2 args: pattern and replacement\n")
25+
}
26+
27+
pattern := os.Args[1]
28+
replacement := os.Args[2]
29+
if err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
30+
if err != nil {
31+
return err
32+
}
33+
34+
if info.IsDir() {
35+
return nil
36+
}
37+
38+
dir, file := filepath.Split(path)
39+
if x := strings.Index(file, pattern); x >= 0 {
40+
// pattern freebsd
41+
// replacement netbsd
42+
// file libc_freebsd_amd64.go
43+
// replaced libc_netbsd_amd64.go
44+
// 01234567890123456789
45+
// 1
46+
// x 5
47+
file = file[:x] + replacement + file[x+len(pattern):]
48+
dst := filepath.Join(dir, file)
49+
b, err := os.ReadFile(path)
50+
if err != nil {
51+
return fmt.Errorf("reading %s: %v", path, err)
52+
}
53+
54+
if err := os.WriteFile(dst, b, 0640); err != nil {
55+
return fmt.Errorf("writing %s: %v", dst, err)
56+
}
57+
fmt.Printf("%s -> %s\n", path, dst)
58+
}
59+
60+
return nil
61+
}); err != nil {
62+
fail(1, "%s", err)
63+
}
64+
}

benchmark/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Benchmarks
2+
The benchmarking is conducted against CGo implementation of SQLite driver (https://github.com/mattn/go-sqlite3).
3+
4+
Benchmark tests are inspired by and closely repeat those described in https://www.sqlite.org/speed.html.
5+
6+
## Doing benchmarks
7+
Benchmarks are run by custom runner and invoked with
8+
```console
9+
go test -v .
10+
```
11+
Additional command line arguments:
12+
13+
| flag | type | default | description |
14+
| ---- | ---- | ------- | ----------------------------------------------------------------------------------------------- |
15+
| -mem | bool | false | if true: benchmarks will use in-memory SQLite instance, otherwise: on-disk instance |
16+
| -rep | uint | 1 | run each benchmark multiple times and average the results. this may provide more stable results |
17+
18+
19+
## Current results
20+
```text
21+
=== RUN Test_BenchmarkSQLite
22+
23+
goos: darwin
24+
goarch: amd64
25+
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
26+
repeat: 1 time(s)
27+
in-memory SQLite: false
28+
29+
bench_create_index | 1.80x | CGo: 120.880 ms/op | Pure-Go: 217.574 ms/op
30+
bench_select_on_string_comparison | 2.25x | CGo: 19.326 ms/op | Pure-Go: 43.498 ms/op
31+
bench_select_with_index | 5.84x | CGo: 0.002 ms/op | Pure-Go: 0.014 ms/op
32+
bench_select_without_index | 1.50x | CGo: 6.071 ms/op | Pure-Go: 9.111 ms/op
33+
bench_insert | 1.17x | CGo: 0.481 ms/op | Pure-Go: 0.565 ms/op
34+
bench_insert_in_transaction | 1.78x | CGo: 0.004 ms/op | Pure-Go: 0.006 ms/op
35+
bench_insert_into_indexed | 1.62x | CGo: 0.008 ms/op | Pure-Go: 0.013 ms/op
36+
bench_insert_from_select | 1.80x | CGo: 30.409 ms/op | Pure-Go: 54.703 ms/op
37+
bench_update_text_with_index | 3.26x | CGo: 0.004 ms/op | Pure-Go: 0.013 ms/op
38+
bench_update_with_index | 4.20x | CGo: 0.003 ms/op | Pure-Go: 0.011 ms/op
39+
bench_update_without_index | 1.40x | CGo: 6.421 ms/op | Pure-Go: 9.010 ms/op
40+
bench_delete_without_index | 1.28x | CGo: 180.734 ms/op | Pure-Go: 231.105 ms/op
41+
bench_delete_with_index | 1.85x | CGo: 34.284 ms/op | Pure-Go: 63.569 ms/op
42+
--- PASS: Test_BenchmarkSQLite (171.62s)
43+
```

0 commit comments

Comments
 (0)