Code Monkey home page Code Monkey logo

go-sqlite's Introduction

badge badge
Hits

Pure-Go SQLite driver for GORM

Pure-go (without cgo) implementation of SQLite driver for GORM

This driver has SQLite embedded, you don't need to install one separately.

Usage

import (
  "github.com/glebarez/sqlite"
  "gorm.io/gorm"
)

db, err := gorm.Open(sqlite.Open("sqlite.db"), &gorm.Config{})

In-memory DB example

db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})

Foreign-key constraint activation

Foreign-key constraint is disabled by default in SQLite. To activate it, use connection URL parameter:

db, err := gorm.Open(sqlite.Open(":memory:?_pragma=foreign_keys(1)"), &gorm.Config{})

More info: https://www.sqlite.org/foreignkeys.html

FAQ

How is this better than standard GORM SQLite driver?

The standard GORM driver for SQLite has one major drawback: it is based on a Go-bindings of SQLite C-source (this is called cgo). This 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). 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.).
  • Because of C-compiler requirement, you can't build your Go code inside tiny stripped containers like (golang-alpine)
  • Building on GCP is not possible because Google Cloud Platform does not allow gcc to be executed.

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.

Is this tested good ?

Yes, The CI pipeline of this driver employs whole test base of GORM, which includes more than 12k tests (see badge on the page-top). Testing is run against latest major releases of Go:

  • 1.18
  • 1.19

In following environments:

  • Linux
  • Windows
  • MacOS

Is it fast?

Well, it's slower than CGo implementation, but not terribly. See the bechmark of underlying pure-Go driver vs CGo implementation.

Included features

go-sqlite's People

Contributors

glebarez avatar dependabot[bot] avatar jinzhu avatar black-06 avatar saeidee avatar a631807682 avatar robhafner avatar moredure avatar paulvollmer avatar d-rickyy-b avatar samuelncui avatar theta-dev avatar ggxxll avatar cncal avatar dino-ma avatar duc-cnzj avatar testwill avatar labulakalia avatar zakaria-chahboun avatar c-bata avatar moul avatar k4leung4 avatar jortel avatar francoliberali avatar fclairamb avatar bfabio avatar tekkamanendless avatar re-cheid avatar chrisportman avatar mtfelian avatar

Stargazers

Masuda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.