gchaincl / Dotsql
Licence: gpl-2.0
A Golang library for using SQL.
Stars: ✭ 579
Programming Languages
go
31211 projects - #10 most used programming language
Labels
Projects that are alternatives of or similar to Dotsql
Falcon
Free, open-source SQL client for Windows and Mac 🦅
Stars: ✭ 4,848 (+737.31%)
Mutual labels: sql
Tidyexplain
🤹♀ Animations of tidyverse verbs using R, the tidyverse, and gganimate
Stars: ✭ 558 (-3.63%)
Mutual labels: sql
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (-6.91%)
Mutual labels: sql
Tiny tds
TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
Stars: ✭ 575 (-0.69%)
Mutual labels: sql
Gdut Course
广东工业大学计算机学院课程攻略 - 毕业设计、校招、课程设计、实验、经验分享、论文模板、试卷、习题解答等等
Stars: ✭ 533 (-7.94%)
Mutual labels: sql
Yugabyte Db
The high-performance distributed SQL database for global, internet-scale apps.
Stars: ✭ 5,890 (+917.27%)
Mutual labels: sql
Jinjasql
Template Language for SQL with Automatic Bind Parameter Extraction
Stars: ✭ 529 (-8.64%)
Mutual labels: sql
Beam
Apache Beam is a unified programming model for Batch and Streaming
Stars: ✭ 5,149 (+789.29%)
Mutual labels: sql
Datasette
An open source multi-tool for exploring and publishing data
Stars: ✭ 5,640 (+874.09%)
Mutual labels: sql
Jailer
Database Subsetting and Relational Data Browsing Tool.
Stars: ✭ 576 (-0.52%)
Mutual labels: sql
dotsql
A Golang library for using SQL.
It is not an ORM, it is not a query builder. Dotsql is a library that helps you keep sql files in one place and use it with ease.
Dotsql is heavily inspired by yesql.
Installation
$ go get github.com/gchaincl/dotsql
Usage
First of all, you need to define queries inside your sql file:
-- name: create-users-table
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name VARCHAR(255),
email VARCHAR(255)
);
-- name: create-user
INSERT INTO users (name, email) VALUES(?, ?)
-- name: find-users-by-email
SELECT id,name,email FROM users WHERE email = ?
-- name: find-one-user-by-email
SELECT id,name,email FROM users WHERE email = ? LIMIT 1
--name: drop-users-table
DROP TABLE users
Notice that every query has a name tag (--name:<some name>
),
this is needed to be able to uniquely identify each query
inside dotsql.
With your sql file prepared, you can load it up and start utilizing your queries:
// Get a database handle
db, err := sql.Open("sqlite3", ":memory:")
// Loads queries from file
dot, err := dotsql.LoadFromFile("queries.sql")
// Run queries
res, err := dot.Exec(db, "create-users-table")
res, err := dot.Exec(db, "create-user", "User Name", "[email protected]")
rows, err := dot.Query(db, "find-users-by-email", "[email protected]")
row, err := dot.QueryRow(db, "find-one-user-by-email", "[email protected]")
stmt, err := dot.Prepare(db, "drop-users-table")
result, err := stmt.Exec()
You can also merge multiple dotsql instances created from different sql file inputs:
dot1, err := dotsql.LoadFromFile("queries1.sql")
dot2, err := dotsql.LoadFromFile("queries2.sql")
dot := dotsql.Merge(dot1, dot2)
Embeding
To avoid distributing sql
files alongside the binary file, you will need to use tools like
gotic to embed / pack everything into one file.
TODO
- [ ] Enable text interpolation inside queries using
text/template
SQLX
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].