Cross-posted from “What would be the best way to store the country of a user in SQL?” by @lena@gregtech.eu in !learn_programming@programming.dev
I use Gorm. This is the current code:
package main
import (
"fmt"
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Env struct {
DB *gorm.DB
Logger *log.Logger
}
type User struct {
ID uint
Username string
Name string
Email string
PasswordHash string
Country string //should probably be a foreign key of another table
}
func initDB() {
env := &Env{}
db, err := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
if err != nil {
fmt.Printf("Error opening database: %v", err)
return
}
env.DB = db
env.DB.AutoMigrate(&User{})
}
func main() {
initDB()
}
As you can see in the comment in the code, I assume the best way would be to have a table of countries and then assign each user to one via a foreign key. However, it seems a bit cumbersome to manually create a list of all countries. Is there a better way to do this?
Store a jpg of the country’s flag as binary
You’re supposed to use PNG for images of that sort, you fucking barbarian.
I’ll use a gif with each frame being a different country flag. Then I can access them by frame index.
That’s what you got emoji for.
Well shit, that’s weirdly viable.
It really is.
Better use FHD png to keep the quality.
This is the only real way to do it, the other solutions involve “standards” which more often than not aren’t all encompassing. Make sure that any user input of a country is just them uploading the jpg of their home country without any sort of validationbecausee everyone is loyal to their home country.
This should be the standard :)