basic internal structure
This commit is contained in:
32
internal/database/main.go
Normal file
32
internal/database/main.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func InitDB(db *sql.DB) {
|
||||
schema := `
|
||||
CREATE TABLE IF NOT EXISTS currencies (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
code TEXT NOT NULL UNIQUE,
|
||||
name TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS companies (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
shares_outstanding INTEGER NOT NULL,
|
||||
price REAL NOT NULL,
|
||||
currency_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (currency_id) REFERENCES currencies(id)
|
||||
);`
|
||||
|
||||
if _, err := db.Exec(schema); err != nil {
|
||||
log.Fatal("Failed to create tables:", err)
|
||||
}
|
||||
fmt.Println("Tables ready")
|
||||
}
|
||||
Reference in New Issue
Block a user