v1.2.0: back: first use of gorm for the database

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2024-03-30 11:07:41 +01:00
commit 8861c369cc
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
4 changed files with 52 additions and 0 deletions

28
internal/databases.go Normal file
View file

@ -0,0 +1,28 @@
package logins
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type Users struct {
Username string `gorm:"primaryKey"`
Email string `gorm:"unique:users_email_key"`
Password string `gorm:""`
}
func test(tx *gorm.DB) *gorm.DB {
return tx.Table("users")
}
func Init_database() {
dsn := "postgres://acc:totor@postgres:5432/accounts?sslmode=disable"
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
fmt.Println(test(db))
db.AutoMigrate(&Users{})
}