简体   繁体   English

使用 GO GORM 创建动态 SQL 表

[英]Dynamic SQL Table creation with GO GORM

I need to create some SQL tables using go package gorm.我需要使用 go package gorm 创建一些 SQL 表。 The structures of these tables are unknown until describing data (or direct data) are given.在给出描述数据(或直接数据)之前,这些表的结构是未知的。 So, I need to create table with gorm , without using struct .所以,我需要用 gorm创建表,而不使用 struct

Is it possible to do that?有可能这样做吗? Or maybe is it possible to create a struct with reflect and use it to create the table?或者也许可以使用反射创建一个结构并使用它来创建表?

Thank you for your help.谢谢您的帮助。

GORM has package GORM有package

migrator Migrator has the following function迁移器 迁移器有以下 function

func (m Migrator) CreateTable(values ...interface{}) error

It accepts interface for table creation, so you can play with some map and that CreateTable func它接受用于创建表的接口,因此您可以使用一些 map 和 CreateTable func

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM