package sites import ( "database/sql" "fmt" ) const createSitesTable = `CREATE TABLE IF NOT EXISTS sites ( url TEXT NOT NULL PRIMARY KEY, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, name TEXT NOT NULL );` func CreateTable(db *sql.DB) { if _, err := db.Exec(createSitesTable); err != nil { fmt.Println(fmt.Errorf(err.Error())) } } type Site struct { created_at uint64 Name string Url string } const upsertQuery = `INSERT INTO sites (url, name) VALUES (?, ?) ON CONFLICT (url) DO UPDATE SET name = excluded.name ` func (s *Site) Save(db *sql.DB) { db.Exec(upsertQuery, s.Url, s.Name) }