Beego dynamically creates objects in models using database table names

  golang, question

This is a struct defined in models, and the database name in beego is test_books_type

package models
 
 import (
 "github.com/astaxie/beego/orm"
 )
 
 type Books_type struct {
 Guid      string `orm:"pk"`
 Top_guid  string
 Type_name string
 }
 
 func init() {
 orm.RegisterModelWithPrefix("test_", new(Books_type))
 }

The current situation is that I have multiple models files and have seen many structs. Each struct corresponds to one database table with the prefix test_. How can I create the corresponding model according to the name of the obtained table? ? For example, I got a table named test_movie_type, how do I create new(models.Movie_type), please advise!

There is no need to do this, since we know the table name, we can insert the value directly by using the native statement, or we rely too much on experience and framework, and we should deal with the problem flexibly.