用于读取数据库模式的外部库或迷你语言?

发布于 2024-07-09 06:59:31 字数 377 浏览 6 评论 0原文

我正在考虑为我的妻子编写一个简单的数据库应用程序,但我对良好的编程实践很感兴趣,并且希望有一个人类可读的源来存储数据库模式。

只是,我不知道有什么工具可以完成这项工作,而且我不敢相信它们不存在——可能我只是不知道该问谷歌什么,但我没有找到它们。

那么,有哪些库或其他工具支持从纯文本文件读取数据库模式。


对于 invenetix 的问题:我希望在构建时生成数据库创建代码,或者在版本中包含架构描述,并在运行时根据描述构建数据库。 Draemon 的建议没问题,但如果我能帮助的话,我不想被锁定在预定的 RDBMS 中。

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

可能我现在已经过度设计这个问题了。

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.


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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

爱情眠于流年 2024-07-16 06:59:31

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

这适用于 mysql、postgresql、oracle 以及可能任何其他数据库。

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.

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

半寸时光 2024-07-16 06:59:31

我想我现在明白了一些。

尽管市场上的每个 SQL 解决方案都应遵守一定程度的 ANSI SQL 标准合规性,但它们都将提供某种可能无法在其他 SQL Server 解决方案中共享/使用/识别的自定义数据类型。

例如,在 MySQL 4 中,您可以使用多种选择(DATE、DATETIME、TIME、YEAR 和 TIMESTAMP),而在 MS SQL 2000 中,您只有几个选择(DATETIME 或 SMALLDATETIME)。 您必须确保最终生成的模式在您愿意支持的解决方案之间是通用的。

MySQL 数据类型

MS SQL 2000 数据类型

这有帮助吗?

I think I understand a bit better now.

Eventhough each SQL solution on the market should adhere to some level of the ANSI SQL standards compliance, they'll all provide some sort of custom data type that might not be shared/used/recognized in another SQL server solution.

Like for example, in MySQL 4 you'd have quite a selection to use (DATE, DATETIME, TIME, YEAR, and TIMESTAMP) whereas in MS SQL 2000, you'd only have a couple (DATETIME or SMALLDATETIME). You'd have to ensure which ever schema you'd end up generating is common between the solutions you're willing to support.

MySQL Data Types

MS SQL 2000 Data Types

Does this help?

隱形的亼 2024-07-16 06:59:31

SQLite 不以文本格式保存数据,但它可能会做你喜欢的事情。

它非常适合嵌入式数据库 - 没有服务器,无需设置,并且数据库位于可由您的应用程序管理的单个文件中。

http://www.sqlite.org/

SQLite doesn't keep its data in text format, but it will probably do what you like.

It's perfect for an embedded database -- there are no servers, no setup, and the database is in a single file that can be managed by your application.

http://www.sqlite.org/

寄风 2024-07-16 06:59:31

您可能需要查看 http://www.codesmithtools.com/ 。 该工具旨在读取数据库的架构,并允许您基于该架构创建代码模板。 它有一个用于访问模式数据的抽象库。

You may want to check out http://www.codesmithtools.com/ . The tool is designed to read the schema of a database and allow you to create code templates based on that schema. It has an abstract library for accessing schema data.

饭团 2024-07-16 06:59:31

我还无法发表评论,但如果我理解正确的话,您希望应用程序或库根据文本文件中提供的数据构建模式?

您能否提供您想要完成的示例工作流程? 您遇到问题的是哪一步?

I'm unable to give comments yet, but if I understand this right, you want an application or library to build a schema dependent on the data provided in the text file?

Could you provide a sample work flow in which you're seeking to accomplish? Which step is the one you're having the issue with?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文