aboutsummaryrefslogtreecommitdiffstats
path: root/webstats/queries.sql
blob: 5e16da04f70491c91d803ff0f69e366a685d6ee1 (plain)
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
28
29
30
31
32
#lang cl-yesql/sqlite

-- name: create-stats-table
-- Creates table for tracking visits
CREATE TABLE IF NOT EXISTS STATS (
    timestamp int DEFAULT (unixepoch()) NOT NULL,
    click text,
    page text,
    referrer text,
    ip text,
    user_agent text,
    title text)

-- name: drop-stats-table
-- Removes table tracking visits
DROP TABLE IF EXISTS STATS

-- name: insert @last-id
-- Insert a data point
INSERT INTO STATS (click, page, referrer, ip, user_agent, title)
    VALUES (:click, :page, :referer, :ip, :user_agent, :title)


-- name: activity-stats
-- timeseries of activity
SELECT
    (timestamp / 600) * 600 AS time,
    count(*)
FROM
    STATS
GROUP BY
    1;