-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (31 loc) · 816 Bytes
/
main.go
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
33
34
35
36
/*
Copyright © 2024 Nikolas Molinari <[email protected]>
*/
package main
import (
"database/sql"
"fmt"
"github.com/Gavin152/crewcut/cmd"
_ "modernc.org/sqlite"
"os"
)
func main() {
createDB()
cmd.Execute()
}
func createDB() {
Db, _ := sql.Open("sqlite", "data.db")
defer Db.Close()
createTrips, _ := Db.Prepare("CREATE TABLE IF NOT EXISTS crews (id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL)")
_, err := createTrips.Exec()
if err != nil {
fmt.Printf("Failed to create table: %v\n", err)
os.Exit(1)
}
createUsers, _ := Db.Prepare("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT, crewId INTEGER, FOREIGN KEY(crewId) REFERENCES crews (id))")
_, err = createUsers.Exec()
if err != nil {
fmt.Printf("Failed to create table: %v\n", err)
os.Exit(1)
}
}