mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 23:44:22 +00:00
Implement time since query
This commit is contained in:
@@ -266,7 +266,7 @@ func (q *Query) Placeholder(arg any) *Query {
|
|||||||
func (q *Query) Placeholders(n int) *Query {
|
func (q *Query) Placeholders(n int) *Query {
|
||||||
placeholders := make([]string, n)
|
placeholders := make([]string, n)
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := range n {
|
||||||
q.pos++
|
q.pos++
|
||||||
if q.dbType == DBTypePostgres {
|
if q.dbType == DBTypePostgres {
|
||||||
placeholders[i] = fmt.Sprintf("$%d", q.pos)
|
placeholders[i] = fmt.Sprintf("$%d", q.pos)
|
||||||
@@ -279,6 +279,14 @@ func (q *Query) Placeholders(n int) *Query {
|
|||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *Query) TimeSince(days int) string {
|
||||||
|
if q.dbType == DBTypePostgres {
|
||||||
|
return fmt.Sprintf("NOW() - INTERVAL '%d days'", days)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("datetime('now', '-%d days')", days)
|
||||||
|
}
|
||||||
|
|
||||||
// AddArgs adds arguments to the query
|
// AddArgs adds arguments to the query
|
||||||
func (q *Query) AddArgs(args ...any) *Query {
|
func (q *Query) AddArgs(args ...any) *Query {
|
||||||
q.args = append(q.args, args...)
|
q.args = append(q.args, args...)
|
||||||
|
|||||||
Reference in New Issue
Block a user