A Go SQL query builder and struct mapper.
godb is a simple Go query builder and struct mapper, not a full-featured ORM. godb does not manage relationships.
Initially, godb was a learning project. The goal was to improve my Go skills by doing some useful things. But more and more features have been added and godb has become a serious project that can be used by others.
godb is a project that is still young and evolving. The API is almost stable, but it can still change slightly from one version to another. Each new version is associated with a tag, so it is possible to target a particular one if necessary.
RETURNING support for PostgreSQL.OUTPUT support for SQL Server.db.UseErrorParser())Println(...) method)db.SetDefaultTableNamer(yourFn). Supported types are: Plural,Snake,SnakePlural. You can also define TableName() string method to for your struct and return whatever table name will be.I made tests of godb on differents architectures and operating systems : OSX, Windows, Linux, ARM (Cortex A7) and Intel x64.
The current version of godb is compatible from Go 1.13 to 1.19. Older versions through 1.10 to 1.12 are supported by the v1.0.14 tag .
There are three forms of documentation :
dbtests/common, which are run on the different databases supported.go get github.com/samonzeweb/godbInstall the required driver (see tests). You cas use multiple databases if needed.
Of course you can also use a dependency management tool like dep.
godb tests use GoConvey and at least SQLite :
go get github.com/smartystreets/goconvey
go get github.com/mattn/go-sqlite3To run tests, go into the godb directory and executes go test ./...
SQLite tests are done with in memory database, it's fast. You can run tests with others databases, see below.
With the exception of SQLite, all drivers are pure Go code, and does not require external dependencies.
Install the driver and set the GODB_POSTGRESQL environment variable with the PostgreSQL connection string.
go get github.com/lib/pq
GODB_POSTGRESQL="your connection string" go test ./...Install the driver and set the GODB_MYSQL environment variable with the MySQL connection string.
go get github.com/go-sql-driver/mysql
GODB_MYSQL="your connection string" go test ./...Install the driver and set the GODB_MSSQL environment variable with the SQL Server connection string.
go get github.com/denisenkom/go-mssqldb
GODB_MSSQL="your connection string" go test ./...Using Docker you can test with SQLite, PostgreSQL, MariaDB and SQL Server with the testallwithdocker.sh shell script.
SQL Server is greedy, on OSX allow at least 4Go to Docker.
The example below illustrates the main features of godb.
You can copy the code into an example.go file and run it. You need to create the database and the books table as explained in the code.
…Released under the MIT License, see LICENSE.txt for more informations.
No open issues yet, or sync has not completed.