Code Monkey home page Code Monkey logo

bqb's People

Contributors

allanglen avatar benjic avatar henrikpoulsen avatar nullism 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

bqb's Issues

Error in subquery gets lost

I am really enjoying this project.

One issue I noticed very early is that if there's an error in a separate subquery it does not propagate when added to an outer query.

See this test I wrote to illustrate the issue

func TestErrorSubquery(t *testing.T) {
	// One more ? than we are passing args for which is wrong and should fail
	subQuery := New("SELECT id FROM table2 WHERE id = ? and value = ?", 1)

	// It gives an error when the query is directly turned to sql which is good
	_, _, err := subQuery.ToSql()
	if err == nil || !strings.Contains(err.Error(), "extra ? in text") {
		t.Errorf("expected error for subquery")
	}

	// But if you pass it into another query instead there is no error and the sql it spits out will be
	// "SELECT * FROM table WHERE id IN ()" which is not what I would expect
	q := New("SELECT * FROM table WHERE id IN (?)", subQuery)
	_, _, err = q.ToSql()
	if err == nil {
                // It fails here
		t.Errorf("expected error for subquery")
	}
}

Is it possible to get it to check the sub queries for errors and return those instead of ignoring them?

Performance issue with Query.ToMysql

I have a query with over 10000 parameters in "names", unfortunately, I have a usecase with 10000 ids in IN statement. And query.ToMysql() takes 3 mins to return the results. Is there any recommendation for the number of parameters?

My code is like:

deviceUUIDFromValue := bqb.New(`
SELECT device_id FROM devices_parameters 
WHERE TYPE = ?
AND value IN (?)`, sourceTypeMap[type], names)

filterForEnvOperator := createEnvIDQuery(request.EnvOperatorMap)

deviceUUIDFromOperator := bqb.New(`
SELECT device_id FROM devices_operators 
WHERE device_id IN (?) ?`, deviceUUIDFromValue, filterForEnvOperator)


query := bqb.New(`
SELECT t1.data, t2.value, t3.operator_id, t3.env_id FROM audit_device t1 
JOIN devices_parameters t2 ON t2.device_id = t1.device_id 
JOIN devices_operators t3 ON t3.device_id = t1.device_id
WHERE t1.device_id IN (?)
ORDER BY t1.id DESC`, deviceUUIDFromOperator)


sql, params, err := query.ToMysql()

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.