Masterminds / squirrel

Fluent SQL generation for golang
Other
6.67k stars 458 forks source link

Passing time.Time value type into WHERE arguments #376

Closed badsector998 closed 4 months ago

badsector998 commented 4 months ago

I want to simply insert the values into WHERE conditions as follows:

msTable := sq.Select("*").From("sensor_measurements").Where("measured_at >= '?'", startTime).Where("measured_at <= '?'", endTime)

Value type is standard time.Time and query string after .ToSql(), the question mark is persist instead generated into complete query string with values intended. Am I missing something?

SELECT * FROM sensor_measurements WHERE measured_at >= '2024-02-01 01:00:00' AND measured_at <= '2024-02-01 02:00:00'

Originally, the complete query intended as follows:

SELECT * FROM sensor_measurements WHERE measured_at BETWEEN '2024-02-01 01:00:00' AND '2024-02-01 02:00:00'

Intended query will be executed into MySQL database using *gorm.DB.Raw()

badsector998 commented 4 months ago

nvm, just remove the single quote and feed the args from ToSQL() to gorm scan.