Skip to content
Snippets Groups Projects
Unverified Commit a88cb6fd authored by Cseh Viktor's avatar Cseh Viktor
Browse files

Is over for today

parent 32c584c0
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true"> <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="PostgreSQL - backend_db@localhost" uuid="719cc097-78f3-4981-b64f-a7946da0d6b8"> <data-source source="LOCAL" name="database" uuid="719cc097-78f3-4981-b64f-a7946da0d6b8">
<driver-ref>postgresql</driver-ref> <driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize> <synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver> <jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://localhost:5432/backend_db</jdbc-url> <jdbc-url>jdbc:postgresql://localhost:5432/</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir> <working-dir>$ProjectFileDir$</working-dir>
</data-source> </data-source>
</component> </component>
......
package db package dbHelper
import ( import (
"gorm.io/driver/postgres" "gorm.io/driver/postgres"
...@@ -6,17 +6,17 @@ import ( ...@@ -6,17 +6,17 @@ import (
"mobwebhf/models" "mobwebhf/models"
) )
func Dbinit() *gorm.DB { func Dbinit() *gorm.DB {
dsn := "host=localhost user=postgres password=almafa dbname=backend_db port=5432 sslmode=disable TimeZone=Europe/Budapest" dsn := "host=localhost user=postgres password=almafa port=5432 sslmode=disable TimeZone=Europe/Budapest"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil { if err != nil {
panic("failed to connect database") panic("failed to connect database")
} }
asd := db.AutoMigrate(&models.Question{}) asd := db.AutoMigrate(&models.Question{})
if asd != nil { if asd != nil {
} }
return db return db
} }
docker run -p 5432:5432 --name backend_db -e POSTGRES_PASSWORD=almafa -d postgres
\ No newline at end of file
...@@ -3,7 +3,7 @@ package main ...@@ -3,7 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"mobwebhf/db" "mobwebhf/dbHelper"
) )
func something(c *gin.Context){ func something(c *gin.Context){
...@@ -14,7 +14,7 @@ func something(c *gin.Context){ ...@@ -14,7 +14,7 @@ func something(c *gin.Context){
func main() { func main() {
fmt.Println("alma") fmt.Println("alma")
db := db.Dbinit() db := dbHelper.Dbinit()
if db != nil { if db != nil {
print(db) print(db)
} }
......
package routes
package routes
package routes
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment