v1.2.0: back: first use of gorm for the database
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
ba64038d70
commit
8861c369cc
4 changed files with 52 additions and 0 deletions
28
internal/databases.go
Normal file
28
internal/databases.go
Normal 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{})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue