~evanj/cms

ref: 4e6befbb576c2e14bcbb5b05e127ae40c9c6073e cms/internal/s/db/action.go -rw-r--r-- 632 bytes
4e6befbbEvan J Fix(hook service): Hook service was broke for list of hooks. Encapsulate 1 year, 25 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package db

import (
	"time"

	"git.sr.ht/~evanj/cms/internal/m/org"
)

func (db *DB) ActionNew(o org.Org, at time.Time) error {
	_, err := db.Exec("INSERT INTO cms_action (ORG_ID, AT) VALUES (?, ?)", o.ID(), at.Format("2006-01-02 03:04:05"))
	return err
}

func (db *DB) ActionGetCount(o org.Org, from, to time.Time) (int, error) {
	var (
		count int
		q     = "SELECT COUNT(*) FROM cms_action WHERE cms_action.ORG_ID=? AND AT>? AND AT<?"
	)

	a := from.Format("2006-01-02 03:04:05")
	b := to.Format("2006-01-02 03:04:05")
	if err := db.QueryRow(q, o.ID(), a, b).Scan(&count); err != nil {
		return 0, err
	}

	return count, nil
}