Grails,如何在运行时使用方言创建表 [英] Grails, How Create Table in Run-time Using Dialect

查看:167
本文介绍了Grails,如何在运行时使用方言创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在运行时创建表,而不必担心不同数据库的创建表专有语法以及可以由GORM或Hibernate管理的其他事物?

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 ?

我需要在运行时动态创建和管理索引表,不需要ORM。

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

推荐答案

看来这个问题在问题如何在grails中创建动态域类。然而,Burt对动态域类插件的回答似乎被放弃了。

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.

我建议现在使用raw SQL,如 SQL Groovy文档
这是一个快速示例(确保您的数据库ID具有适当的权限)

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()

这篇关于Grails,如何在运行时使用方言创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆