- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用 TypeORM 建立了一个 Typescript 项目,但我在编译时遇到了一些问题。
我的包结构是这样的:
root
├── db
│ ├── migrations
│ │ ├── a_migration.ts
│ ├── connection
│ │ ├── config.ts <- ormconfig
│ │ ├── encrypt.ts
│ │ ├── index.ts <- creates the connection
├── src
│ ├── card
│ │ ├── entity.ts
├── package.json
├── tsconfig.json
我的 config.ts 是:
export = {
type: 'postgres',
host: POSTGRES_HOST,
port: POSTGRES_PORT,
username: POSTGRES_USER,
password: POSTGRES_PASS,
database: POSTGRES_DB,
synchronize: true,
logging: false,
entities: ['**src/**/*entity.{ts,js}'],
migrations: ['**/migrations/*.{ts,js}'],
cli: {
entitiesDir: 'src/entity',
migrationsDir: 'db/migrations',
},
namingStrategy: new SnakeNamingStrategy(),
};
tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"target": "es6",
"module": "CommonJS",
"allowJs": false,
"esModuleInterop": true,
"noImplicitAny": true,
"resolveJsonModule": true,
"outDir": "./build",
"strict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"include": ["./src/*", "./db/*"],
"exclude": ["./**/__tests__/*", "./**/__functionaltests__/*"]
}
我尝试更换
**
实体和迁移中的前缀为
path.join
+
__dirname
但随后 typeorm 无法检测到迁移文件和实体。我知道这与解析代码在
build
下的路径有关。文件夹,但我不确定如何解决这个问题。
nodemon
但不适用于已编译的(js)之一。
SyntaxError: Cannot use import statement outside a module
任何帮助表示赞赏,非常感谢!
最佳答案
你的实体和迁移应该被赋予 build 目录而不是 src 目录。
和synchronize
应该设置为假。
尝试更新您的config.ts
如下所示:
export = {
type: 'postgres',
host: POSTGRES_HOST,
port: POSTGRES_PORT,
username: POSTGRES_USER,
password: POSTGRES_PASS,
database: POSTGRES_DB,
synchronize: false,
logging: false,
entities: ['build/src/**/*entity.{ts,js}'],
migrations: ['build/db/migrations/*.{ts,js}'],
cli: {
entitiesDir: 'src/entity',
migrationsDir: 'db/migrations',
},
namingStrategy: new SnakeNamingStrategy(),
};
注意
entities
中的更改和
migrations
特性。如果这不起作用,很可能是因为我指定的路径不在
build
中。目录。在这种情况下,请根据需要进行更改。
关于javascript - typescript & TypeORM : Cannot use import statement outside a module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67546054/
我知道 typeorm 可以创建整个 db 模式,甚至可以将数据库模式与实体定义同步(请参阅 synchronize 中的 Connection Options ) 但在生产中,我想要求 typeor
我有一个 Role Entity 和一个 Route Entity,它们是树形结构,它们是 ManyToMany 关系。 现在我想通过 RoleRepository.find({relations:
我已经设置了 logging: true当createConnection()来自 TypeORM ,在大多数情况下都可以正常工作。 但是有一种情况,我的数据字段之一来自特定的 query/mutat
在 Rails 上,每个测试用例都会创建一个 ActiveRecord 事务,它允许测试所有内容,然后将数据库恢复到原始状态,而不必删除所有表或任何可能影响播种机等的内容。 可以在 Typeorm 上
Note 与 Subject 具有多对多关系 查询它的最佳方式是什么?我喜欢编写以下内容来获取给定注释上的所有主题: const subjectRepo = connection.getRepos
我使用 UUID 作为我的实体的主键,它工作得很好。但我想删除那些破折号。 现在 ID 被保存为 8e5365f4-3d42-4274-bafc-93b97bd6e3f2 36 个字符 我想要的是 8
我一整天都在尝试将实体保存到 MySQL 数据库中,遇到了巨大的困难。我正在使用 NestJS 和 TypeORM。 teacher.entity.ts import { BeforeInsert,
我也想在前端使用我用 TypeORM 创建的实体。有没有一种干净的方法可以做到这一点?或者我应该继续这样做。 此时,我的文件结构如下所示(前端的 Angular 8): /server /enti
我想得到一个 basic setup使用 TypeORM 工作,并在设置后收到此错误。 这是一个 REPL(只需执行 yarn install && yarn db:dev 后跟 yarn db:mi
我正在尝试通过 Nest/TypeORM 构建 SAAS 产品,我需要按子域配置/更改数据库连接。 customer1.domain.com => connect to customer1 datab
如何将 TypeORM 与 Better-sqlite3 一起使用? 上官方documentation ,有一个section形式更好-sqlite3。 我已经通过 typeorm@latest 安装
操作系统:macOS Sierra v 10.12.6 我正在尝试使用 typeorm 在 Typescript 中构建一个应用程序,这是我第一次使用其中任何一个。 我使用了以下两种方法来安装 typ
有没有一种简单的方法可以使用 DataSource 在 typeORM v.0.3.6 中播种数据? typeorm-seeding 似乎使用已弃用的 Connection。 最佳答案 找到这个包裹
我正在做一门类(class),我们使用 express-node postgres 和 react(使用 typescript)和 typeORM。到目前为止一切都运行良好,但我面临 typeORM
尽管进行了大量研究和反复试验,但不幸的是,我还没有针对以下用例的完美解决方案:一个用户有多个帖子,这被正确地实现为一对多关系。我想为用户加载他的所有帖子,但不是帖子的所有属性,只有某些属性。 方法 1
我用 NestJS 和 ORM TypeORM 做一个 API 我有实体: 用户 关系类型 UserRelationshipType(带有用户和关系类型 ForeignKey) 和关系(与 userR
我有两个实体 Tag 和 Photo: // tag.entity.ts import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm
我有以下要保存的实体: @Entity('approvals') export class Approval { @PrimaryGeneratedColumn() id: string;
我有命令: .leftJoinAndSelect("permission.user", "user") .where("permissi
我是使用 typeorm 的新手,这是我第二次与 typeorm 混淆,我有以下查询: SELECT t1.a,t1.b,t2.a (SELECT TOP 1 t1.a FROM table1
我是一名优秀的程序员,十分优秀!