Grails, How Create Table in Run-time Using Dialect

无人久伴 提交于 2020-02-04 09:00:21

问题


Is it possible to create tables in run-time without being worry about create table proprietary syntax of different databases and other things that can be managed by GORM or Hibernate ?

I need to create and manage somes table dynamically in run-time and don't need to ORM for them.


回答1:


Hey it seems this question was asked in the question how can i create a dynamic domain class in grails. Yet Burt's answer of the dynamic domain class plugin seems to be abandoned.

I would recommend using raw SQL for now as described in the SQL Groovy Docs. Here is a quick example (make sure your database id has proper permissions)

def sql = new Sql(dataSource)

sql.execute '''
    create table PROJECT (
        id integer not null,
        name varchar(50),
        url varchar(100),
    )
    ''' 
sql.close()


来源:https://stackoverflow.com/questions/30192096/grails-how-create-table-in-run-time-using-dialect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!