qustavo / dotsql Goto Github PK
View Code? Open in Web Editor NEWA Golang library for using SQL.
License: GNU General Public License v2.0
A Golang library for using SQL.
License: GNU General Public License v2.0
Something like this
DB.Raw("SELECT * FROM users WHERE name1 = @name OR name2 = @name2 OR name3 = @name",
sql.Named("name", "jinzhu1"), sql.Named("name2", "jinzhu2")).Find(&user)
I need to update several tables at once and would like that to be in one transaction. Can't seem to figure out how dotsql and transactions can play together nicely and noticed you have no examples either. Thoughts?
Hi, as I can see from todos, you are intended to support sqlx, so many time passed, how's going on?
Let's say we use comments to group sql queries
Example
-- file user.sql
--- UPDATE QUERIES ---
--name: EmailUpdate
UPDATE users SET email = $1 where user_id = $2
--name: LevelUpdate
UPDATE users SET level = $1 where user_id = $2
--- REPORTS ---
...
In current implementation --- REPORTS---
comment belongs to LevelUpdate
query. Problem is when LevelUpdate
is not complete and we update the query on the program side. Let's imagine t hat we have the following:
--name: LevelUpdate
UPDATE users SET level = $1 where user_id IN
and in the application:
q := queries.LevelUpdate + fmt.Sprintf(" (%s)", strings.Join(userIDs, ","))
This will fail: ERROR: syntax error at end of input (SQLSTATE 42601)
- because queries.LevelUpdate
is finishing with a comment. I know that we can bind here the sqlx
solution, however this is just a simple example.
--end
I'm trying to load in a sql file from my package relative to the current package path:
tables, err := dotsql.LoadFromFile("../sql/tables.sql")
if err != nil {
fmt.Println(err)
fmt.Println("failed at tables")
os.Exit(1)
}
This is erroring out with file not found, but it's the right path. Any tips?
Edit: Is it always relative to where the main is? Wondering if I just specify relative to main when I build the bundle the files into the binary using gotic after the fact so I can still have a single static binary.
I'm getting this error when trying to use the public method LoadFromString
import (
"github.com/gchaincl/dotsql"
)
_, err = dotsql.LoadFromString("--name: query-a")
if err != nil {
return
}
dotsql.LoadFromString undefined (type *dotsql.DotSql has no field or method LoadFromString)
Hi,
I have just started looking at this project and I've had a couple of ideas. I wanted to see what your thoughts are and if the ideas are in line with where you are taking this project.
What do you think about exposing lookupQuery, so that callers can retrieve the SQL?
What about exposing the ability to get all of the loaded query names?
How about adding a method to add queries after the initial file is loaded?
Perhaps have the ability for dotsql to write out a valid config file that includes these newly added queries?
I guess I am seeing it as a potential query manager, but perhaps that should be a higher level application that just uses dotsql?
So let's say we have set of queries that we know are able to run on mysql/postgres/sqlite3. But we also have queries that uses specific engine extensions.
So I'm looking for a confortable way to implement this, I'm not sure if an extra tag (@krisajenkins?) is the right way to do it, or expose a DotSql.Merge()
method that allows to add more queries to the actual loader.
Ideas will be appreciated :)
INSERT INTO 'dirs' ('id', 'name', 'parent_id') VALUES
('1', 'data1', '0'),
('2', 'data2', '1'),
('3', 'data3', '2'),
('4', 'data4', '3');
dotsql can achieve this function?
for example:
-- name: batch-insert-dirs
INSERT INTO 'dirs' ('id', 'name', 'parent_id') VALUES ?;
var dirs []Dir = []Dir{}
...
dirs = append(dirs, dir)
...
_, err := dot.Exec(db, batch-insert-dirs, dirs)
As soon as there is a chance to break API, I would like to propose to change semantics for Load() - and generalize the code to use Reader interface instead of sticking with os.File. And provide handy wrapper LoadFile() of course.
Typical use case - if app needs only a few queries, it would be nice to have them in plaintext directly in code (maybe, create also LoadString() wrapper). Also, if we want to bundle dotSQL-file into the app, using go-bindata - it's would require reading from Asset, and not from os.File.
And it's generally wise to use Reader in such cases.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.