简体   繁体   English

从现有的 ArangoDB 数据库自动生成模型定义

[英]Auto-generate model definitions from existing ArangoDB database

I'm using ArangoDB 3.4 and planning to use an MVC framework like Backbone.js (or whatever is recommended).我正在使用 ArangoDB 3.4 并计划使用像 Backbone.js(或任何推荐的)这样的 MVC 框架。 Is there a way to auto-generate the models from the existing database to reduce the amount of boilerplate code I have to write by hand?有没有办法从现有数据库自动生成模型以减少我必须手动编写的样板代码量?

For example, I am looking at the aye-aye TodoMVC demo .例如,我正在查看aye-aye TodoMVC 演示 It has this model:它有这个模型:

const joi = require('joi');

exports.Model = {
  _key: joi.string().optional(),
  _id: joi.string().optional(),
  _rev: joi.string().optional(),
  completed: joi.boolean().optional(),
  order: joi.number().optional(),
  title: joi.string().optional()
};

Writing a few by hand is no problem.手写几个是没有问题的。 My database will ultimately require many of these models.我的数据库最终将需要许多这些模型。 Are there any tools that I can use with ArangoDB that will help automate this by producing scaffold code?是否有任何工具可以与 ArangoDB 一起使用,通过生成脚手架代码来帮助自动化?

What I have in mind is possibly something like Python's inspectdb command:我想到的可能类似于 Python 的inspectdb命令:

inspectdb检查数据库

Introspects the database tables in the database pointed-to by the DATABASE_NAME setting and outputs a Django model module (a models.py file) to standard output.内省 DATABASE_NAME 设置指向的数据库中的数据库表,并将 Django 模型模块(models.py 文件)输出到标准输出。

Use this if you have a legacy database with which you'd like to use Django.如果您有一个要使用 Django 的旧数据库,请使用此选项。 The script will inspect the database and create a model for each table within it.该脚本将检查数据库并为其中的每个表创建一个模型。

As you might expect, the created models will have an attribute for every field in the table.正如您所料,创建的模型将具有表中每个字段的属性。

If there are entirely different approaches to doing this with ArangoDB and javascript please point me in the right direction.如果使用 ArangoDB 和 javascript 执行此操作有完全不同的方法,请指出正确的方向。

django-admin inspectdb [table [table ...]] targets relational databases where tables have schema and because of that it's possible to generate model django-admin inspectdb [table [table ...]]目标关系数据库,其中表具有模式,因此可以生成模型

ArangoDB is NoSQL with schemaless collections with ability to store various JSON documents types and because of that you'll need to get schema per document type. ArangoDB 是具有无模式集合的 NoSQL,能够存储各种 JSON 文档类型,因此您需要获取每种文档类型的模式。

While using fullstack javascript approach you can put your model in js module and use it on both front and backend.在使用全栈 javascript 方法时,您可以将模型放在 js 模块中并在前端和后端使用它。

for us, most reliable and scalable approach is based on Typescript as master with following-ish workflow对我们来说,最可靠和可扩展的方法是基于 Typescript 作为 master 和以下工作流程

then you can然后你可以

  • generate JSON Schema via typescript-json-schema通过typescript-json-schema生成 JSON Schema
  • generate UML diagram with tsviz使用tsviz生成 UML 图
  • convert JSON Schema to joi with enjoi使用enjoi将 JSON Schema 转换为joi
  • generate forms from JSON schema (front-end framework specific)从 JSON 模式生成表单(特定于前端框架)

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

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