28 lines
538 B
Go
28 lines
538 B
Go
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{})
|
|
}
|