ArangoDB 的哪些部分是用 Node-GYP 完成的 [英] What parts of ArangoDB are done with Node-GYP

查看:41
本文介绍了ArangoDB 的哪些部分是用 Node-GYP 完成的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在弄清楚 ArangoDB 的结构,以确定它是否可以成为我的长期解决方案.

I am figuring out the structure of ArangoDB to be sure whether it could be my long term solution.

我的一个重要问题是,哪些部分由 node-gyp(或 Node-Addon)构成 - 查询构建器如何将 JavaScript 生成的 AQL 查询转换为与原生一样快?

One of my important questions is, what parts are made by node-gyp (or Node-Addon) - and how does the query-builder transforms JavaScript generated AQL queries to be fast as native?

我知道我自己也可以更深入地研究代码,但我认为如果一些核心开发人员能回答这个问题(或解释他们如何向 JavaScript 和 AQL 公开功能),速度会快得多.

I know I also could go deeper into the code myself, but I think it is much faster if some of the core developers would answer this (or explain how they expose functionality to JavaScript and AQL).

我认为很多人负责分析 ArangoDB 很有趣.(我们的工作不是相信营销用语和基准……我们必须了解它是如何运作的).

I think it is interesting for many people are responsible to analyze ArangoDB. (Our job is not to belief marketing phrases and benchmarks... we have to understand how it works).

我的主要目标是将 ArangoDB 视为 JavaScript 开发人员.

My major goal is to look at ArangoDB as an JavaScript developer.

推荐答案

ArangoDB 不是由 node 或 gyp 组成的.但是 ArangoDB 使用谷歌的 V8 JavaScript 引擎来执行 JavaScript 代码,就像 node.js 一样.

ArangoDB is not made of node or gyp. But ArangoDB uses Google's V8 JavaScript engine to execute JavaScript code, the same as node.js does.

这意味着您可以在 ArangoDB 中运行用户定义的 JavaScript 代码,它会被 V8 即时编译为本机代码.ArangoDB 自己的一些模块也是用 JavaScript 编写的.一些第三方 JavaScript 模块,包括一些由 node.js 和 npm 使用或编写的模块,也与 ArangoDB 捆绑在一起.

That means you can run user-defined JavaScript code inside ArangoDB, and it will be compiled to native code by V8 on the fly. Some of ArangoDB's own modules are written in JavaScript, too. Several third-party JavaScript modules, including a few modules used by or written for node.js and npm, are bundled with ArangoDB, too.

关于与 node.js 和 npm 模块的兼容性:

Regarding compatibility with node.js and npm modules:

来自 node.js 和 npm 的模块也可以在 ArangoDB 中工作,只要它们不依赖于 node.js 内部或来自其他模块的代码.这意味着所有只有 JavaScript 并且不需要任何特定于节点的东西的模块都应该在 ArangoDB 中工作.joi 就是一个很好的例子.依赖于 node.js 特定对象或 node.js 的 C++ 扩展的 node.js/npm 模块在 ArangoDB 中不起作用.

modules from node.js and npm work in ArangoDB too as long as they do not rely on node.js internals or code from other modules that do. That means all modules that are JavaScript only and do not require any node specific stuff should work in ArangoDB. joi is a good example for this. node.js/npm modules that rely on node.js-specific object or C++ extensions for node.js will not work in ArangoDB.

ArangoDB 本身是用 C++ 编写的,它的一些模块是用 JavaScript 编写的.通过 V8 包装器对象和函数,用户定义的 JavaScript 代码和捆绑的 ArangoDB JavaScript 模块可以访问 ArangoDB 的内部结构.这些函数是 C++ 函数,它们通过告诉 V8 它们存在而暴露给 JavaScript.

ArangoDB itself is written in C++, with some its modules being written in JavaScript. ArangoDB's internals are made accessible to user-defined JavaScript code and the bundled ArangoDB JavaScript modules by V8 wrapper objects and functions. These functions are C++ functions that are exposed to JavaScript by telling V8 that they exist.

这是一个示例:ArangoDB 公开了一个名为 db 的 JavaScript 对象.这个对象有一些预定义的功能,例如_collection().当这个函数被调用时,这实际上是对一个 C++ 函数的调用,然后它可以处理它的(JavaScript)参数,在这种情况下应该是一个集合名称字符串.在 C++ 函数内部,将查找指定名称的集合.如果未找到,该函数将返回一个 JavaScript null 对象.如果找到,该函数将返回一个集合对象,该对象封装在所谓的 V8 外部 中.对于 JavaScript 代码,这看起来像一个普通对象,但这个对象又具有一些 C++ 绑定.

Here's an example: ArangoDB exposes a JavaScript object named db. This object has some predefined functions, e.g. _collection(<name>). When this function is called, this will effectively be a call to a C++ function, which can then handle its (JavaScript) arguments, which in this case should be a collection name string. Inside the C++ function there will then be a lookup for the collection of the specified name. If not found, the function will return a JavaScript null object. If found, the function will return a collection object, wrapped in a so-called V8 external. For the JavaScript code, this will look like a regular object, but this object has some C++ bindings again.

为了使所有这些工作,服务器将在开始时在 V8 上下文中注册 db 对象,并为所有对象的方法注册包装函数.它会为其他对象和函数这样做,因此服务器内部有一个完整的 JavaScript API.

In order for all this to work, the server will register the db object in a V8 context at start, and also register the wrapper functions for all the object's methods. It will do so for other objects and functions, so there is a full JavaScript API for the server internals.

AQL 是 ArangoDB 的查询语言,是用 C++ 编写的,将按原样执行.然而,一些 AQL 函数和运算符是在 JavaScript 中实现的.如果 AQL 查询使用此类函数或运算符,则会生成查询特定的 JavaScript 片段,使用 V8 即时编译并执行.此外,AQL 查询可以使用用户定义的 JavaScript 函数进行计算.这些函数是常规的 JavaScript 函数,必须先用命令注册,然后才能在查询中使用.这些函数的调用如上,生成并执行一段动态JavaScript代码来调用用户自定义函数.

AQL, ArangoDB's query language, is written in C++ and will be executed as such. Some AQL functions and operators however are implemented in JavaScript. If an AQL query makes use of such function or operator, a query-specific JavaScript snippet will be generated, compiled on the fly using V8 and executed. Additionally, AQL queries can make use of user-defined JavaScript functions for calculations. These functions are regular JavaScript functions, which must be registered with a command before they can be used in a query. Invocation of these functions is as above, with a piece of dynamic JavaScript code being generated and executed to call the user-defined function.

最后,ArangoDB 的 Foxx 框架是用 JavaScript 编写的,允许在 ArangoDB 服务器中定义 HTTP 路由.这些路由背后的动作是用户定义的,可以通过上述方式访问服务器内部和数据库数据.

Finally, ArangoDB's Foxx framework is written in JavaScript and allows defining HTTP routes in the ArangoDB server. The actions behind these routes are user-defined, and can have access to the server internals and database data via the beforementioned way.

这篇关于ArangoDB 的哪些部分是用 Node-GYP 完成的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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