mirror of
https://github.com/glebarez/sqlite.git
synced 2025-09-27 03:55:53 +08:00
update readme + workflows
This commit is contained in:
52
.github/workflows/badge-gorm-tests.yml
vendored
Normal file
52
.github/workflows/badge-gorm-tests.yml
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
name: Badge GORM tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["GORM-tests"]
|
||||||
|
branches: [master]
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create-gorm-tests-badge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Download artifact
|
||||||
|
uses: dawidd6/action-download-artifact@v2
|
||||||
|
with:
|
||||||
|
workflow: gorm-tests.yml
|
||||||
|
workflow_conclusion: completed
|
||||||
|
path: .
|
||||||
|
|
||||||
|
- name: Prepare badge data
|
||||||
|
working-directory: Linux-1.17-tests.out
|
||||||
|
run: |
|
||||||
|
echo "tests_passed=$(cat ./*.out | grep PASS | wc -l)" >> $GITHUB_ENV
|
||||||
|
echo "tests_skipped=$(cat ./*.out | grep SKIP | wc -l)" >> $GITHUB_ENV
|
||||||
|
echo "tests_failed=$(cat ./*.out | grep FAIL | wc -l)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Make success badge
|
||||||
|
if: ${{ env.tests_failed == '0' }}
|
||||||
|
uses: schneegans/dynamic-badges-action@v1.1.0
|
||||||
|
with:
|
||||||
|
auth: ${{ secrets.GIST_SECRET }}
|
||||||
|
gistID: fb4d23f63d866b3e1e58b26d2f5ed01f
|
||||||
|
filename: badge-gorm-tests.json
|
||||||
|
label: GORM tests
|
||||||
|
message: "Passed: ${{ env.tests_passed }} | Failed: ${{ env.tests_failed }}"
|
||||||
|
color: 54a158
|
||||||
|
style: for-the-badge
|
||||||
|
labelColor: 25292d
|
||||||
|
|
||||||
|
- name: Make fail badge
|
||||||
|
if: ${{ env.tests_failed != '0' }}
|
||||||
|
uses: schneegans/dynamic-badges-action@v1.1.0
|
||||||
|
with:
|
||||||
|
auth: ${{ secrets.GIST_SECRET }}
|
||||||
|
gistID: fb4d23f63d866b3e1e58b26d2f5ed01f
|
||||||
|
filename: badge-gorm-tests.json
|
||||||
|
label: GORM tests
|
||||||
|
message: "Passed: ${{ env.tests_passed }} | Failed: ${{ env.tests_failed }}"
|
||||||
|
color: 96232b
|
||||||
|
style: for-the-badge
|
||||||
|
labelColor: 25292d
|
41
.github/workflows/badge-sqlite-version.yml
vendored
Normal file
41
.github/workflows/badge-sqlite-version.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
name: Badge Sqlite version
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["GORM-tests"]
|
||||||
|
branches: [master]
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
create-sqlite-version-badge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: go mod package cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-${{ hashFiles('go.mod') }}
|
||||||
|
|
||||||
|
- name: request sqlite_version()
|
||||||
|
run: echo "sqlite_version=$(go test . -run '^TestSQLiteVersion$' -v | grep sqlite_version | tr -s ' ' | cut -d' ' -f3)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Make version badge
|
||||||
|
uses: schneegans/dynamic-badges-action@v1.1.0
|
||||||
|
with:
|
||||||
|
auth: ${{ secrets.GIST_SECRET }}
|
||||||
|
gistID: fb4d23f63d866b3e1e58b26d2f5ed01f
|
||||||
|
filename: badge-sqlite-version.json
|
||||||
|
label: SQLite
|
||||||
|
message: "${{ env.sqlite_version }}"
|
||||||
|
color: 2269d3
|
||||||
|
style: for-the-badge
|
||||||
|
labelColor: 25292d
|
2
.github/workflows/gorm-tests.yml
vendored
2
.github/workflows/gorm-tests.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go: ['1.17']
|
go: ['1.17']
|
||||||
platform: [ubuntu-latest]
|
platform: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
42
README.md
42
README.md
@@ -1,7 +1,28 @@
|
|||||||
# Pure-Go GORM Sqlite driver
|

|
||||||
Pure-go (without cgo) implementation of SQLite driver for [GORM](https://gorm.io)
|

|
||||||
|
|
||||||
## Usage
|
# Pure-Go GORM Sqlite driver
|
||||||
|
Pure-go (without cgo) implementation of SQLite driver for [GORM](https://gorm.io)<br>
|
||||||
|
|
||||||
|
## How is this better than standard GORM SQLite driver?
|
||||||
|
The [standard GORM driver for SQLite](gorm.io/driver/sqlite) has one major drawback: it is based on a [Go-bindings of SQLite C-source](https://github.com/mattn/go-sqlite3) (this is called [cgo](https://go.dev/blog/cgo])). That fact imposes following restrictions on Go developers:
|
||||||
|
- to build and run your code, you will need a C compiler installed on a machine
|
||||||
|
- SQLite has many features that need to be enabled at compile time (e.g. [json support](https://www.sqlite.org/json1.html)). If you are using those features, you will need to include proper go build tags for every go command to work properly (go run, go test, etc.). Such tweaks may be easy to forget / hard to achieve (e.g. in automated environments like universal CI pipelines for Go)
|
||||||
|
- Because of C-compiler requirement, you can't build your Go code inside tiny stripped containers like (golang-alpine)
|
||||||
|
|
||||||
|
|
||||||
|
# FAQ
|
||||||
|
### Is this tested good ?
|
||||||
|
Yes, The CI pipeline of this driver employs [whole test base](https://github.com/go-gorm/gorm/tree/master/tests) of GORM, which includes for than **12k** tests (see badge on the page-top)
|
||||||
|
|
||||||
|
### SQLite is written in C, why don't we need a cgo ?
|
||||||
|
This driver is based on pure-Go implementation of SQLite (https://gitlab.com/cznic/sqlite), which is basically an original SQLite C-source AST, translated into Go! So, you may be sure you're using the original SQLite implementation under the hood.
|
||||||
|
|
||||||
|
### Is JSON feature of SQLite enabled?
|
||||||
|
Yes!
|
||||||
|
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
@@ -9,25 +30,18 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
db, err := gorm.Open(sqlite.Open("file:sqlite.db"), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open("sqlite.db"), &gorm.Config{})
|
||||||
```
|
```
|
||||||
|
|
||||||
### In-memory DB example
|
### In-memory DB example
|
||||||
```go
|
```go
|
||||||
db, err := gorm.Open(sqlite.Open("file::memory:"), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Foreign-key constraint activation
|
### Foreign-key constraint activation
|
||||||
Foreign-key constraint is disabled by default in SQLite. To activate it, use connection parameter:
|
Foreign-key constraint is disabled by default in SQLite. To activate it, use connection URL parameter:
|
||||||
```go
|
```go
|
||||||
db, err := gorm.Open(sqlite.Open("file::memory:?_pragma=foreign_keys(1)"), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open(":memory:?_pragma=foreign_keys(1)"), &gorm.Config{})
|
||||||
```
|
```
|
||||||
More info: [https://www.sqlite.org/foreignkeys.html](https://www.sqlite.org/foreignkeys.html)
|
More info: [https://www.sqlite.org/foreignkeys.html](https://www.sqlite.org/foreignkeys.html)
|
||||||
|
|
||||||
### Shared cache
|
|
||||||
You also might want to enable shared cache:
|
|
||||||
```go
|
|
||||||
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
|
|
||||||
```
|
|
||||||
More info: [https://www.sqlite.org/sharedcache.html](https://www.sqlite.org/sharedcache.html)
|
|
||||||
|
|
||||||
|
23
sqlite_version_test.go
Normal file
23
sqlite_version_test.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package sqlite
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSQLiteVersion(t *testing.T) {
|
||||||
|
var version string
|
||||||
|
|
||||||
|
db, err := sql.Open(DriverName, ":memory:")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
row := db.QueryRow("select sqlite_version()")
|
||||||
|
if row.Scan(&version) != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(version)
|
||||||
|
}
|
Reference in New Issue
Block a user