我浏览了NPM上的TypeORM快速入门,网址为:https://www.npmjs.com/package/typeorm
我添加了一些代码来尝试原始SQL查询,但我立即收到QueryFailedError。
我验证了表和实体是使用TypeORM的connection.manager的find方法创建的,并且我还通过pgAdmin手动检查了表。为了达到良好的效果,我使用pgAdmin生成了初始SQL,然后对其进行了最小程度的修改。
我还验证了ormconfig.json文件中的syncy设置为true。
import "reflect-metadata";
import {createConnection} from "typeorm";
import {User} from "./entity/User";
createConnection().then(async connection => {
const user = new User();
user.firstName = "Timber";
user.lastName = "Saw";
user.age = 25;
await connection.manager.save(user);
let data = await connection.query(
`SELECT firstName FROM public.user;`
);
}).catch(error => console.log(error));
QueryFailedError: column "firstname" does not exist
...
message: 'column "firstname" does not exist',
name: 'QueryFailedError',
length: 108,
severity: 'ERROR',
code: '42703',
detail: undefined,
hint: undefined,
position: '8',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '3293',
routine: 'errorMissingColumn',
query: 'SELECT firstName FROM user;',