80 lines
1.5 KiB
Go
80 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"strings"
|
|
|
|
"git.pablu.de/pablu/sqv-engine/sql"
|
|
)
|
|
|
|
func main() {
|
|
s := `
|
|
CREATE TABLE TEST(
|
|
ID text PRIMARY KEY
|
|
);
|
|
|
|
CREATE TABLE sessions (
|
|
session_id text PRIMARY KEY,
|
|
access_token text NOT NULL,
|
|
user_email text NOT NULL,
|
|
FOREIGN KEY(user_email) REFERENCES users(email)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
email text PRIMARY KEY,
|
|
username text
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
session_id text PRIMARY KEY,
|
|
access_token text NOT NULL,
|
|
user_email text NOT NULL,
|
|
FOREIGN KEY(user_email) REFERENCES users(email)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS game_settings (
|
|
lobby_id text PRIMARY KEY,
|
|
max_players integer,
|
|
game_mode text,
|
|
selected_playlist_id text
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS lobbys (
|
|
lobby_id text PRIMARY KEY,
|
|
host_email text,
|
|
game_settings_id text,
|
|
FOREIGN KEY(game_settings_id) REFERENCES game_settings(lobby_id),
|
|
FOREIGN KEY(host_email) REFERENCES users(email)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS users_in_lobbys (
|
|
user_email text PRIMARY KEY,
|
|
lobby_id text,
|
|
FOREIGN KEY(user_email) REFERENCES users(email),
|
|
FOREIGN KEY(lobby_id) REFERENCES lobbys(lobby_id)
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS auth_states (
|
|
state_id text PRIMARY KEY,
|
|
code_verifier text NOT NULL
|
|
);
|
|
`
|
|
|
|
parser := sql.NewParser(strings.NewReader(s))
|
|
|
|
for {
|
|
stmt, err := parser.Parse()
|
|
if err != nil && errors.Is(err, io.EOF) {
|
|
fmt.Println("Finished parsing")
|
|
break
|
|
} else if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
stmt.Print()
|
|
}
|
|
}
|