Compare commits
No commits in common. "6d0f27eba7be8c941a004fc975467a75666af7bc" and "0ea09941a5a7c71c955fd637383fe64a902e9fdc" have entirely different histories.
6d0f27eba7
...
0ea09941a5
3
.gitignore
vendored
3
.gitignore
vendored
@ -21,5 +21,4 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
dist
|
dist
|
||||||
*.sqlite3
|
|
11
main.go
11
main.go
@ -5,17 +5,20 @@ import (
|
|||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"lewisdale.dev/oopsie/data"
|
"lewisdale.dev/oopsie/data"
|
||||||
"lewisdale.dev/oopsie/ping"
|
|
||||||
"lewisdale.dev/oopsie/sites"
|
"lewisdale.dev/oopsie/sites"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const createSitesTable = `CREATE TABLE IF NOT EXISTS sites (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
url TEXT NOT NULL
|
||||||
|
);`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
db := data.Connect("test.sqlite3")
|
db := data.Connect("test.sqlite3")
|
||||||
|
|
||||||
db.Exec("PRAGMA foreign_keys = ON;")
|
|
||||||
|
|
||||||
sites.CreateTable(db)
|
sites.CreateTable(db)
|
||||||
ping.CreateTable(db)
|
|
||||||
|
|
||||||
site := sites.Site{Name: "Lewisdale.dev", Url: "https://lewisdale.dev"}
|
site := sites.Site{Name: "Lewisdale.dev", Url: "https://lewisdale.dev"}
|
||||||
site.Save(db)
|
site.Save(db)
|
||||||
|
58
ping/ping.go
58
ping/ping.go
@ -1,58 +0,0 @@
|
|||||||
package ping
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"lewisdale.dev/oopsie/sites"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Status int16
|
|
||||||
|
|
||||||
const (
|
|
||||||
Success Status = iota
|
|
||||||
Failure
|
|
||||||
)
|
|
||||||
|
|
||||||
type Ping struct {
|
|
||||||
Site sites.Site
|
|
||||||
Timestamp string
|
|
||||||
Status Status
|
|
||||||
}
|
|
||||||
|
|
||||||
const createQuery = `CREATE TABLE IF NOT EXISTS statuses (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
name TEXT NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS ping (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
||||||
site TEXT NOT NULL,
|
|
||||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
status INTEGER NOT NULL,
|
|
||||||
FOREIGN KEY (site) REFERENCES sites(url),
|
|
||||||
FOREIGN KEY (status) REFERENCES statuses(id)
|
|
||||||
);`
|
|
||||||
|
|
||||||
const seedStatusQuery = `INSERT INTO statuses (id, name) VALUES (?, ?)
|
|
||||||
ON CONFLICT (id) DO NOTHING`
|
|
||||||
|
|
||||||
func CreateTable(db *sql.DB) {
|
|
||||||
if _, err := db.Exec(createQuery); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
seedStatuses(db)
|
|
||||||
}
|
|
||||||
|
|
||||||
func seedStatuses(db *sql.DB) {
|
|
||||||
if _, err := db.Exec(seedStatusQuery, Success, "Success"); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if _, err := db.Exec(seedStatusQuery, Failure, "Failure"); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Ping) Save(db *sql.DB) {
|
|
||||||
|
|
||||||
}
|
|
BIN
test.sqlite3
Normal file
BIN
test.sqlite3
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user