I’m developing an application that initially will be talking to a Mysql database but will also need to connect to Postgres and possible Oracle. I’m using Gorm to provide abstraction and facilitate easily changing the database type w/o updating the code.
I was curious in Go if it was possible to define a type struct (a Gorm table model) by specifying the struct fields in an external JSON or config file of some sort?
Example:
{
"tables": [
{
"name": "mytable",
"constraints": [],
"indexes": []
"columns": [
"id": {"type": "varchar", "size": 20, "options": { "autoincr": true, "not null": true },
...
]
}
],
}
Take something like that and at runtime somehow create a Gorm object.
type MyTable struct {
gorm.Model // I can actually do without using this Gorm builtin structure if this is an issue
Id string `gorm:"type:varchar(40);not null"`
}
Thanks for any help