Git Product home page Git Product logo

dotsql's People

Contributors

divan avatar forging2012 avatar hxzhao527 avatar kayrein avatar msoap avatar ondrowan avatar qustavo avatar swithek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dotsql's Issues

Is it possible to use named parameter?

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)

Transaction support?

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?

Dose sqlx supported?

Hi, as I can see from todos, you are intended to support sqlx, so many time passed, how's going on?

Add a mark to finish query

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.

We need a phrase to end the query, eg: --end

Unable to load .sql files from a relative path?

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.

Can't access LoadFromString

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)

Some questions

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?

Load engine-dependent queries

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 :)

batch insert

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)

Generalize Load() API call to use io.Reader interface

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.

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.