0.2.2 insert into db fiorst iteration hardcoded
This commit is contained in:
@@ -1,11 +1 @@
|
|||||||
{
|
just in case i ducked up .gitignore
|
||||||
"database": {
|
|
||||||
"host": "localhost",
|
|
||||||
"port": "5432",
|
|
||||||
"user": "postgres",
|
|
||||||
"password": "postgres",
|
|
||||||
"dbname": "ti1",
|
|
||||||
"sslmode": "disable"
|
|
||||||
},
|
|
||||||
"temp": "value"
|
|
||||||
}
|
|
||||||
23
database/ServiceDeliveryDB.go
Normal file
23
database/ServiceDeliveryDB.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InsertServiceDelivery(db *sql.DB) (int, error) {
|
||||||
|
fmt.Println("Inserting ServiceDelivery...")
|
||||||
|
var id int
|
||||||
|
|
||||||
|
responseTimestamp := "2024-05-25T10:24:29.353864654+02:00"
|
||||||
|
recordedAtTime := "2024-05-25T10:24:29.353864654+02:00"
|
||||||
|
|
||||||
|
err := db.QueryRow("INSERT INTO public.ServiceDelivery (ResponseTimestamp, RecordedAtTime) VALUES ($1, $2) RETURNING ID", responseTimestamp, recordedAtTime).Scan(&id)
|
||||||
|
fmt.Println(err)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
fmt.Println("ID:", id)
|
||||||
|
fmt.Println("ServiceDelivery inserted successfully!")
|
||||||
|
return id, nil
|
||||||
|
}
|
||||||
13
main.go
13
main.go
@@ -3,7 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"ti1/config"
|
"ti1/config"
|
||||||
"ti1/data" // Import the data package
|
"ti1/data"
|
||||||
|
"ti1/database"
|
||||||
"ti1/export"
|
"ti1/export"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,7 +12,15 @@ func main() {
|
|||||||
config.PrintDBConfig()
|
config.PrintDBConfig()
|
||||||
config.ConnectToPostgreSQL()
|
config.ConnectToPostgreSQL()
|
||||||
|
|
||||||
data, err := data.FetchData() // Use the FetchData function from the data package
|
db, err := config.ConnectToPostgreSQL()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
//log.Printf("DB: %+v", db)
|
||||||
|
|
||||||
|
database.InsertServiceDelivery(db)
|
||||||
|
|
||||||
|
data, err := data.FetchData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user