Search code examples
gograils-ormgo-gorm

GORM converts query text into lowercase


response := db.Where("createdAt BETWEEN ? AND ?", today, tomorrow).Find(&orders)

I want to make a query with GORM. The column in my table is named "createdAt" but GORM converts it to. "createdat"

    ERROR: column "createdat" does not exist (SQLSTATE 42703)
[172.521ms] [rows:0] SELECT * FROM "Orders" WHERE `createdAt` BETWEEN '2021-04-21 04:00:00' AND '2021-04-22 04:00:00'

How can I prevent GORM from converting the query text to lowercase?


Solution

  • Its not gorm's issue its database issue means in database column is created with name created_at just check there and try replacing your code with this

    response := db.Where("created_at BETWEEN ? AND ?", today, tomorrow).Find(&orders)