用于读取数据库模式的外部库还是迷你语言? [英] External library or mini-language for reading database schema?

查看:53
本文介绍了用于读取数据库模式的外部库还是迷你语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑为我的妻子编写一个简单的数据库应用程序,但是我一直挂在良好的编程习惯上,并且希望有一个人类可读的源来存储数据库模式.

I am considering writing a simple database application for my wife, but I'm hung up on good programming practice, and want to have a human readable source for storing the database schema.

只有,我不知道有什么工具可以工作,而且我不敢相信它们不存在-可能我只是不知道该问什么,但我没有找到他们.

Only, I don't know of any tools for the job, and I can't believe that they don't exist---probably I just don't know what to ask google, but I'm not finding them.

因此,有哪些库或其他工具可以支持从纯文本文件中读取数据库架构.

So, what libraries or other tools out there to support reading database schema from plain text files.

对于invenetix的问题:我希望在构建时生成数据库创建代码,或者在发行版中包含模式描述,并在运行时根据该描述构建数据库.Draemon的建议会很好,但是如果可以的话,我不想被锁定在预定的RDBMS中.

To invenetix's question: I expect to generate the database creation code at build-time or to include the schema description in the release and build the database from the description at run-time. Draemon's suggestion would be fine, but I don't want to be locked into a predetermined RDBMS if I can help it.

也许我应该说我以前在编程项目中使用过数据库,但从未负责过创建代码.

Perhaps I should say that I've used databases in programming projects before, but never been responsible for the creation code.

可能我现在已经解决了这个问题.

Possible I'm over engineering the problem at this point.

推荐答案

只需使用SQL.SQL不仅是查询语言,还是DDL(数据定义语言).例如,如果您使用的是mysql;您可以根据需要设计模式,运行mysqldump,它将使用DDL语句创建一个SQL文件.整理架构,然后可以通过寻找SQL文件随时加载架构.就个人而言,我只是在文本编辑器中编写SQL模式,然后将其加载到mysql中.

Just use SQL. SQL is not only a query language but a DDL (data definition language). If, for example you are using mysql; you can design your schema however you want, run mysqldump which will create an SQL file with DDL statements. Tidy up the schema, then you can load the schema any time you like by sourcing the SQL file. Personally, I just write the SQL schema in a text editor and load it into mysql.

这将适用于mysql,postgresql,oracle和其他任何数据库.

This will work for mysql, postgresql, oracle, and probably any other DB.

这篇关于用于读取数据库模式的外部库还是迷你语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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