简体   繁体   English

将现有数据库与 AdonisJS 一起使用

[英]Use an existing database with AdonisJS

I'm looking to use AdonisJS with an existing database I made.我希望将 AdonisJS 与我制作的现有数据库一起使用。 I only see tutorials and documentation on creating/migrating new tables.我只看到有关创建/迁移新表的教程和文档。 I'm struggling to find online content that shows how to integrate Adonis with a previously created SQL database.我正在努力寻找显示如何将 Adonis 与先前创建的 SQL 数据库集成的在线内容。

I heard it was possible but I do not know how to go about this and fetch the models and sync the orm.我听说这是可能的,但我不知道如何对此进行 go 并获取模型并同步 orm。 How may I do this?我该怎么做?

Adonis can work without migration. Adonis 无需迁移即可工作。

The only thing you have to do on Adonis side is to create your model.在 Adonis 方面,您唯一需要做的就是创建 model。 Be careful and choose right field types.小心并选择正确的字段类型。

To sync your database and models, you have to do it manually.要同步您的数据库和模型,您必须手动进行。 Just create a new model with all fields and the right table name and it's done.只需使用所有字段和正确的表名创建一个新的 model 即可。

After that you can use your models to query database (like before with migrations)之后,您可以使用模型来查询数据库(就像之前的迁移一样)

look at this: https://github.com/ME-Studio/mysql-workbench-export-adonisjs-migrations看看这个: https://github.com/ME-Studio/mysql-workbench-export-adonisjs-migrations

ME-Studio: created a MySQL workbench plugin to automatically generate your migrations from an existing database schema. ME-Studio:创建了 MySQL 工作台插件,以自动从现有数据库模式生成迁移。 Hope this will be useful when you're porting to Adonis.希望这在您移植到 Adonis 时会有用。 mysql-workbench-export-adonisjs-migrations Feedbacks are welcome. mysql-workbench-export-adonisjs-migrations 欢迎反馈。

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

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