L
L
Learn Prog2017-10-17 18:06:52
WordPress
Learn Prog, 2017-10-17 18:06:52

How to make a SQL query with a variable number of parameters?

You need to make a SELECT of the form:

SELECT id,age
FROM users
WHERE age=22 [and gender='m' and ...]

Options may be missing. All combinations do not really want to copy-paste. Which way to look (in Go ) to write normally?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Burduzha, 2019-07-17
@serii81

I've done everything.
It turns out that two closing tags are missing in the header.
It remains to be seen why they disappeared.
The main thing is that it works.
I will remember this lesson for a long time.

A
Alexander Aksentiev, 2017-10-17
@wantknow

https://github.com/Masterminds/squirrel

L
Leonid Nikolaev, 2017-10-17
@nikonor

form a query in any convenient way, put the data into an array of type
var data []interface{}
and then
if r, err = tx.Query(query, data...
) use the syntax for applying an array as a set of parameters

A
Anton Kucherov, 2017-10-17
@DexterHD

https://github.com/avelino/awesome-go#database Choose from here under `SQL query builder, libraries for building and using SQL.` the library that suits you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question