Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Watch
Unwatch
Watching
Releases Only
Ignoring
3
Star
4
Fork
2
EdgeDB
/
内宣
Code
Issues
12
Pull Requests
0
Insights
Pipelines
Service
JavaDoc
PHPDoc
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Join Repository
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
nest.js 项目无法使用 query builder
Backlog
#I5PLN2
xyplayman
Opened this issue
2022-09-04 19:45
尝试在 `nest.js` 项目中使用 `EdgeDB` 的 `Query Builder`,无法运行起来。不过,如果只是使用 `Driver`,可以正常运行以及查询数据库。 问题产生的过程以及现象如下面的描述。 # Docker 环境 初始目录结构如下。 ``` nestjs └── .nest-docker ├── Dockerfile └── docker-compose.yml ``` 其中,`Dockerfile` 在 `node` 的官方镜像的基础上增加了国内源,以及默认安装了 `nest`。 ```docker FROM node:16 RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \ apt update && \ apt install -y net-tools && \ apt install -y ncat && \ apt install -y telnet RUN npm config set registry https://registry.npm.taobao.org && \ yarn config set registry https://registry.npm.taobao.org && \ npm install -g yrm && \ npm i -g @nestjs/cli ``` `docker-compose.yml` 内容如下。 ```docker version: '3' name: nestjs services: nest: build: . container_name: nestjs working_dir: /app environment: NODE_OPTIONS: "--max_old_space_size=3000" volumes: - ..:/app ``` 运行如下命令启动容器。 ```shell docker compose run --rm -p 3000:3000 nest bash ``` 然后在 *容器* 中创建 `nest` 项目。 ```shell cd /app nest new hello ``` # EdgeDB 相关 建立到远程数据库的链接。 ```shell edgedb instance link ``` 初始化项目。 ```shell edgedb project init ``` 创建一个非常简单的 `type`,其中只包含两个简单的 `property`,用于测试。运行 `migration` 相关命令更新数据库。 复制 credentials 文件 `hello.json` 到项目根目录。 在 *容器* 中运行命令安装 `edgedb` 的 npm 包。 ```shell npm install --save edgedb ``` 在 *容器* 中运行命令生成 `Query Builder`。 ```shell npx edgeql-js --credentials-file hello.json ``` 在 `Controller` 中引入相关的模块。 ```typescript import * as edgedb from "edgedb"; import e from "dbschema/edgeql-js"; ``` 编写最简单的查询代码用于测试。 # 运行 ```shell npm run start ``` 在漫长的等待之后,大约有半个小时,提示 out of memory 错误。 ``` <--- Last few GCs ---> [276:0x61cf740] 782691 ms: Mark-sweep 2973.9 (3043.5) -> 2958.7 (3044.2) MB, 1783.3 / 0.0 ms (average mu = 0.293, current mu = 0.222) allocation failure scavenge might not succeed [276:0x61cf740] 785145 ms: Mark-sweep 2974.7 (3044.2) -> 2959.5 (3045.0) MB, 1733.4 / 0.0 ms (average mu = 0.293, current mu = 0.294) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xb02930 node::Abort() [node] 2: 0xa18149 node::FatalError(char const*, char const*) [node] 3: 0xcdd16e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node] 4: 0xcdd4e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node] 5: 0xe94b55 [node] 6: 0xe95636 [node] 7: 0xea3b5e [node] 8: 0xea45a0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 9: 0xea751e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node] 10: 0xe68792 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node] 11: 0xe630ac v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [node] 12: 0xe63185 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [node] 13: 0x10cba0e v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Allocate<v8::internal::Isolate>(v8::internal::Isolate*, int, v8::internal::AllocationType) [node] 14: 0x10cbac3 v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash<v8::internal::Isolate>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashMap>, int) [node] 15: 0x11d7bf5 v8::internal::Runtime_MapGrow(int, unsigned long*, v8::internal::Isolate*) [node] 16: 0x15d5439 [node] Aborted ``` 因为这是一个最小规模的项目,显然不是因为实际内容太多导致。 # 改用 CommonJS 上面的错误应该是编译构建 `TypeScript` 的过程出现问题,因此我尝试着生成 `CommonJS` 代码。删除旧的生成代码后,重新在容器中运行。 ```shell npx edgeql-js --credentials-file hello.json --target cjs ``` 这次不再需要漫长的等待,但是仍然报错如下。 ``` Error: Cannot find module 'dbschema/edgeql-js' Require stack: - /app/hello/dist/app.controller.js - /app/hello/dist/app.module.js - /app/hello/dist/main.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15) at Function.Module._load (node:internal/modules/cjs/loader:804:27) at Module.require (node:internal/modules/cjs/loader:1028:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (/app/hello/src/app.controller.ts:4:1) at Module._compile (node:internal/modules/cjs/loader:1126:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10) at Module.load (node:internal/modules/cjs/loader:1004:32) at Function.Module._load (node:internal/modules/cjs/loader:839:12) at Module.require (node:internal/modules/cjs/loader:1028:19) ``` 不知道我的操作过程是否有误?还请看下 `TypeScript` 和 `CommonJS` 两种方式生成代码,分别应该如何解决此问题。因为两种方式有可能都会用到。前面的使用都还顺利,最后代码无法运行,这个有点始料未及。
尝试在 `nest.js` 项目中使用 `EdgeDB` 的 `Query Builder`,无法运行起来。不过,如果只是使用 `Driver`,可以正常运行以及查询数据库。 问题产生的过程以及现象如下面的描述。 # Docker 环境 初始目录结构如下。 ``` nestjs └── .nest-docker ├── Dockerfile └── docker-compose.yml ``` 其中,`Dockerfile` 在 `node` 的官方镜像的基础上增加了国内源,以及默认安装了 `nest`。 ```docker FROM node:16 RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && \ apt update && \ apt install -y net-tools && \ apt install -y ncat && \ apt install -y telnet RUN npm config set registry https://registry.npm.taobao.org && \ yarn config set registry https://registry.npm.taobao.org && \ npm install -g yrm && \ npm i -g @nestjs/cli ``` `docker-compose.yml` 内容如下。 ```docker version: '3' name: nestjs services: nest: build: . container_name: nestjs working_dir: /app environment: NODE_OPTIONS: "--max_old_space_size=3000" volumes: - ..:/app ``` 运行如下命令启动容器。 ```shell docker compose run --rm -p 3000:3000 nest bash ``` 然后在 *容器* 中创建 `nest` 项目。 ```shell cd /app nest new hello ``` # EdgeDB 相关 建立到远程数据库的链接。 ```shell edgedb instance link ``` 初始化项目。 ```shell edgedb project init ``` 创建一个非常简单的 `type`,其中只包含两个简单的 `property`,用于测试。运行 `migration` 相关命令更新数据库。 复制 credentials 文件 `hello.json` 到项目根目录。 在 *容器* 中运行命令安装 `edgedb` 的 npm 包。 ```shell npm install --save edgedb ``` 在 *容器* 中运行命令生成 `Query Builder`。 ```shell npx edgeql-js --credentials-file hello.json ``` 在 `Controller` 中引入相关的模块。 ```typescript import * as edgedb from "edgedb"; import e from "dbschema/edgeql-js"; ``` 编写最简单的查询代码用于测试。 # 运行 ```shell npm run start ``` 在漫长的等待之后,大约有半个小时,提示 out of memory 错误。 ``` <--- Last few GCs ---> [276:0x61cf740] 782691 ms: Mark-sweep 2973.9 (3043.5) -> 2958.7 (3044.2) MB, 1783.3 / 0.0 ms (average mu = 0.293, current mu = 0.222) allocation failure scavenge might not succeed [276:0x61cf740] 785145 ms: Mark-sweep 2974.7 (3044.2) -> 2959.5 (3045.0) MB, 1733.4 / 0.0 ms (average mu = 0.293, current mu = 0.294) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xb02930 node::Abort() [node] 2: 0xa18149 node::FatalError(char const*, char const*) [node] 3: 0xcdd16e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node] 4: 0xcdd4e7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node] 5: 0xe94b55 [node] 6: 0xe95636 [node] 7: 0xea3b5e [node] 8: 0xea45a0 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node] 9: 0xea751e v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node] 10: 0xe68792 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node] 11: 0xe630ac v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [node] 12: 0xe63185 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [node] 13: 0x10cba0e v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Allocate<v8::internal::Isolate>(v8::internal::Isolate*, int, v8::internal::AllocationType) [node] 14: 0x10cbac3 v8::internal::MaybeHandle<v8::internal::OrderedHashMap> v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash<v8::internal::Isolate>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashMap>, int) [node] 15: 0x11d7bf5 v8::internal::Runtime_MapGrow(int, unsigned long*, v8::internal::Isolate*) [node] 16: 0x15d5439 [node] Aborted ``` 因为这是一个最小规模的项目,显然不是因为实际内容太多导致。 # 改用 CommonJS 上面的错误应该是编译构建 `TypeScript` 的过程出现问题,因此我尝试着生成 `CommonJS` 代码。删除旧的生成代码后,重新在容器中运行。 ```shell npx edgeql-js --credentials-file hello.json --target cjs ``` 这次不再需要漫长的等待,但是仍然报错如下。 ``` Error: Cannot find module 'dbschema/edgeql-js' Require stack: - /app/hello/dist/app.controller.js - /app/hello/dist/app.module.js - /app/hello/dist/main.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15) at Function.Module._load (node:internal/modules/cjs/loader:804:27) at Module.require (node:internal/modules/cjs/loader:1028:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (/app/hello/src/app.controller.ts:4:1) at Module._compile (node:internal/modules/cjs/loader:1126:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10) at Module.load (node:internal/modules/cjs/loader:1004:32) at Function.Module._load (node:internal/modules/cjs/loader:839:12) at Module.require (node:internal/modules/cjs/loader:1028:19) ``` 不知道我的操作过程是否有误?还请看下 `TypeScript` 和 `CommonJS` 两种方式生成代码,分别应该如何解决此问题。因为两种方式有可能都会用到。前面的使用都还顺利,最后代码无法运行,这个有点始料未及。
Comments (
2
)
Sign in
to comment
Status
Backlog
Backlog
Doing
Done
Closed
Assignees
Not set
Labels
Not set
Label settings
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
参与者(2)
1
https://gitee.com/edgedb/devrel.git
git@gitee.com:edgedb/devrel.git
edgedb
devrel
内宣
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register