-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.go
More file actions
30 lines (26 loc) · 719 Bytes
/
Copy pathdb.go
File metadata and controls
30 lines (26 loc) · 719 Bytes
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
package main
import (
"log"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
)
var DB *sqlx.DB
func InitDB() {
var err error
DB, err = sqlx.Open("postgres", "postgres://life_user:life_pass123@localhost:5432/life_science_db?sslmode=disable")
if err != nil {
log.Fatal("Failed to connect to PostgreSQL:", err)
}
_, err = DB.Exec(`CREATE TABLE IF NOT EXISTS events (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
timestamp TIMESTAMP,
processed BOOLEAN DEFAULT FALSE,
location VARCHAR(255),
video_url VARCHAR(255)
)`)
if err != nil {
log.Fatal("Failed to create table:", err)
}
}