github.com/wfusion/gofusion@v1.1.14/common/infra/drivers/orm/sqlite/README.md (about)

     1  ![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/glebarez/fb4d23f63d866b3e1e58b26d2f5ed01f/raw/badge-gorm-tests.json)
     2  ![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/glebarez/fb4d23f63d866b3e1e58b26d2f5ed01f/raw/badge-sqlite-version.json)
     3  <br>[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fglebarez%2Fsqlite&count_bg=%2379C83D&title_bg=%23555555&icon=baidu.svg&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
     4  # Pure-Go SQLite driver for GORM
     5  Pure-go (without cgo) implementation of SQLite driver for [GORM](https://gorm.io/)<br><br>
     6  This driver has SQLite embedded, you don't need to install one separately.
     7  
     8  # Usage
     9  
    10  ```go
    11  import (
    12    "github.com/glebarez/sqlite"
    13    "gorm.io/gorm"
    14  )
    15  
    16  db, err := gorm.Open(sqlite.Open("sqlite.db"), &gorm.Config{})
    17  ```
    18  
    19  ### In-memory DB example
    20  ```go
    21  db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
    22  ```
    23  
    24  ### Foreign-key constraint activation
    25  Foreign-key constraint is disabled by default in SQLite. To activate it, use connection URL parameter:
    26  ```go
    27  db, err := gorm.Open(sqlite.Open(":memory:?_pragma=foreign_keys(1)"), &gorm.Config{})
    28  ```
    29  More info: [https://www.sqlite.org/foreignkeys.html](https://www.sqlite.org/foreignkeys.html)
    30  
    31  # FAQ
    32  ## How is this better than standard GORM SQLite driver?
    33  The [standard GORM driver for SQLite](https://github.com/go-gorm/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)). This fact imposes following restrictions on Go developers:
    34  - to build and run your code, you will need a C compiler installed on a machine
    35  - SQLite has many features that need to be enabled at compile time (e.g. [json support](https://www.sqlite.org/json1.html)). If you plan to use those, you will have to include proper build tags for every ```go``` command to work properly (```go run```, ```go test```, etc.).
    36  - Because of C-compiler requirement, you can't build your Go code inside tiny stripped containers like (golang-alpine)
    37  - Building on GCP is not possible because Google Cloud Platform does not allow gcc to be executed.
    38  
    39  **Instead**, 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.
    40  
    41  ## Is this tested good ?
    42  Yes, The CI pipeline of this driver employs [whole test base](https://github.com/go-gorm/gorm/tree/master/tests) of GORM, which includes more than **12k** tests (see badge on the page-top). Testing is run against latest major releases of Go:
    43  - 1.18
    44  - 1.19
    45  
    46  In following environments:
    47  - Linux
    48  - Windows
    49  - MacOS
    50  
    51  ## Is it fast?
    52  Well, it's slower than CGo implementation, but not terribly. See the [bechmark of underlying pure-Go driver vs CGo implementation](https://github.com/glebarez/go-sqlite/tree/master/benchmark).
    53  
    54  ## Included features
    55  -  JSON1 (https://www.sqlite.org/json1.html)
    56  -  Math functions (https://www.sqlite.org/lang_mathfunc.html)