TypeORM (NestJS/React/Typescript) Column does not exist when joining two Entities with createForeignKeyConstraints: false - entity-framework

Trying to join two entities, with no foreign key created. Thanks in advance.
Entity One, has entity two imported
#Entity("testphotos", {synchronize:false})
export class TestPhotos {
#PrimaryColumn()
photosuserid: number;
#Column()
photosid: number;
#ManyToOne((type) => TestUsers, {createForeignKeyConstraints: false})
testUsers: TestUsers;
}
Entity Two in a different file
#Entity("testusers")
export class TestUsers {
#PrimaryColumn()
userid: number;
#Column()
username: string;
}
In my service
constructor(
#InjectRepository(TestPhotos)
private testRespository: Repository<TestPhotos>,
#InjectDataSource() private readonly datasource: DataSource
) { }
async getPhotoUser(userId: number) {
return await this.testRespository.findOneBy({photosuserid : userId})
}
Error Printout
[Nest] 62148 - 02/09/2023, 2:42:30 PM DEBUG QueryFailedError: column TestPhotos.testUsersUserid does not exist
QueryFailedError: column TestPhotos.testUsersUserid does not exist
at PostgresQueryRunner.query (/Users/christolandry/int-external-apis/src/driver/postgres/PostgresQueryRunner.ts:299:19)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at SelectQueryBuilder.loadRawResults (/Users/christolandry/int-external-apis/src/query-builder/SelectQueryBuilder.ts:3601:25)
at SelectQueryBuilder.executeEntitiesAndRawResults (/Users/christolandry/int-external-apis/src/query-builder/SelectQueryBuilder.ts:3366:26)
at SelectQueryBuilder.getRawAndEntities (/Users/christolandry/int-external-apis/src/query-builder/SelectQueryBuilder.ts:1617:29)
at SelectQueryBuilder.getOne (/Users/christolandry/int-external-apis/src/query-builder/SelectQueryBuilder.ts:1644:25)
at ContentService.getContentByPractice (/Users/christolandry/int-external-apis/src/v1/content/content.service.ts:43:20)
at LegacyContentController.create (/Users/christolandry/int-external-apis/src/v1/content/content.controller.ts:46:21) {
query: 'SELECT "TestPhotos"."photosuserid" AS "TestPhotos_photosuserid", "TestPhotos"."photosid" AS "TestPhotos_photosid", "TestPhotos"."testUsersUserid" AS "TestPhotos_testUsersUserid" FROM "testphotos" "TestPhotos" WHERE ("TestPhotos"."photosuserid" = $1) LIMIT 1',
parameters: [ 1 ],
driverError: error: column TestPhotos.testUsersUserid does not exist
at Parser.parseErrorMessage (/Users/christolandry/int-external-apis/node_modules/pg-protocol/src/parser.ts:369:69)
at Parser.handlePacket (/Users/christolandry/int-external-apis/node_modules/pg-protocol/src/parser.ts:188:21)
at Parser.parse (/Users/christolandry/int-external-apis/node_modules/pg-protocol/src/parser.ts:103:30)
at Socket.<anonymous> (/Users/christolandry/int-external-apis/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (node:events:513:28)
at Socket.emit (/Users/christolandry/int-external-apis/node_modules/dd-trace/packages/datadog-instrumentations/src/net.js:61:25)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Socket.Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
The intent is to get the printout of one user with the associated data from the user table as well.

Related

GitLab pipeline - postgres connection termined unexpectedly

I am having a little trouble with postgres in docker .. I am running this pipeline in gitlab ... and everything starts fine.. I start a postgres:14-alpine docker image and run unit tests of the application ... and when it's about to start (create the test database) ...
I tried increasing the timeouts
pool: {
max: 50,
min: 5,
idle: 600000, // 10min
acquire: 600000,
createTimeoutMillis: 600000,
acquireTimeoutMillis: 600000,
idleTimeoutMillis: 600000,
reapIntervalMillis: 600000,
createRetryIntervalMillis: 600000
}
but it keeps ending up with this "Connection terminated unexpectedly"
Creating database db_unittests, owner will be postgres.
Executing (default): CREATE DATABASE db_unittests WITH OWNER = postgres;
/builds/project/node_modules/sequelize/lib/dialects/postgres/query.js:386
return new sequelizeErrors.DatabaseError(err);
^
DatabaseError [SequelizeDatabaseError]: Connection terminated unexpectedly
at Query.formatError (/builds/project/node_modules/sequelize/lib/dialects/postgres/query.js:386:16)
at Query.run (/builds/project/node_modules/sequelize/lib/dialects/postgres/query.js:87:18)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /builds/project/node_modules/sequelize/lib/sequelize.js:619:16
at async run (/builds/project/tests/scripts/database-recreate.js:50:3) {
parent: Error: Connection terminated unexpectedly
at Connection.<anonymous> (/builds/project/node_modules/pg/lib/client.js:132:73)
at Object.onceWrapper (node:events:627:28)
at Connection.emit (node:events:513:28)
at Socket.<anonymous> (/builds/project/node_modules/pg/lib/connection.js:107:12)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
sql: 'CREATE DATABASE db_unittests WITH OWNER = postgres;',
parameters: undefined
},
original: Error: Connection terminated unexpectedly
at Connection.<anonymous> (/builds/project/node_modules/pg/lib/client.js:132:73)
at Object.onceWrapper (node:events:627:28)
at Connection.emit (node:events:513:28)
at Socket.<anonymous> (/builds/project/node_modules/pg/lib/connection.js:107:12)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
sql: 'CREATE DATABASE db_unittests WITH OWNER = postgres;',
parameters: undefined
},
sql: 'CREATE DATABASE db_unittests WITH OWNER = postgres;',
parameters: undefined
}
Locally, it all works fine .. only in the pipeline - it acting up :disappointed:
Any idea why is that so? Thanks a lot

Unable to start Strapi on MacOS PostgreSQL

System
- Node.js version: v10.19.0
- NPM version: 6.13.4
- Strapi version: 3.0.0-Beta.2
- Database: PostgreSQL 10.11
- Operating system: MacOS Catalina
Describe the bug
I am trying to run local Strapi on my Mac. npm run build works well. However, it has some problems with 'start' and 'develop'. When I am trying to start it by pm2 start npm --name "CMS" -- start, it keeps restarting. I have checked the app OUT-logs and there is a couple of errors e.g.
{ error: syntax error at or near "url"
at Connection.parseE (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:602:11)
at Connection.parseMessage (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:399:19)
at Socket.<anonymous> (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 92,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '50',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1128',
routine: 'scanner_yyerror' }
[2020-04-06T21:30:50.439Z] warn The SQL database indexes haven't been generated successfully. Please enable the debug mode for more details.
{ error: syntax error at or near "name"
at Connection.parseE (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:602:11)
at Connection.parseMessage (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:399:19)
at Socket.<anonymous> (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 93,
severity: 'ERROR',
code: '42601',
detail: undefined,
hint: undefined,
position: '49',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'scan.l',
line: '1128',
routine: 'scanner_yyerror' }
[2020-04-06T21:30:50.439Z] warn The SQL database indexes haven't been generated successfully. Please enable the debug mode for more details.
When I am running npm run start I am getting the following error.
23 ],
__knexQueryUid: '4301a348-badc-484f-a418-4f0f5ab4a2a6',
sql:
'update "core_store" set "key" = ?, "environment" = ?, "tag" = ?, "value" = ?, "type" = ? where "id" = ?',
returning: undefined }
{ method: 'insert',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings:
[ 'development',
'plugin_upload_provider',
'',
'object',
'{"provider":"local","name":"Local server","enabled":true,"sizeLimit":1000000}' ],
__knexQueryUid: '797edf19-aaab-43ff-a2f3-7c25519fb700',
sql:
'insert into "core_store" ("environment", "key", "tag", "type", "value") values (?, ?, ?, ?, ?) returning "id"',
returning: 'id' }
{ method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ 'plugin_users-permissions_advanced', '', '', 1 ],
__knexQueryUid: '51c83527-e289-4c2b-bb0c-48fe7fd34d86',
sql:
'select "core_store".* from "core_store" where "core_store"."key" = ? and "core_store"."environment" = ? and "core_store"."tag" = ? limit ?' }
[2020-04-06T22:20:17.365Z] error error: duplicate key value violates unique constraint "core_store_pkey"
at Connection.parseE (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:602:11)
at Connection.parseMessage (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:399:19)
at Socket.<anonymous> (/usr/local/var/www/trip4share-cms/node_modules/pg/lib/connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! trip4share-cms#1.0.0 start: `strapi start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the trip4share-cms#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Lord-of-the-Mac/.npm/_logs/2020-04-06T22_20_17_400Z-debug.log
The remote version on Linux works well. What should I check?

How to setup another username in database?

I'am a newbie frontend trainee, and I have a task to configure my project on node-typescript-koa-rest. I tried to do my best to configure it, but it has an error.
First of all, I get this project, https://github.com/javieraviles/node-typescript-koa-rest, add here objection.js, knex.js, installed postgresql. After starting my project, I recieve an "TypeORM connection error: error: password authentication failed for user "user" ". From error message I can't get where username for db sets.
On start script.ts is running.
https://pastebin.com/fm0TBaXQ
Where I can change username and password?
Full error message:
TypeORM connection error: error: password authentication failed for user "user"
at Connection.parseE (/home/valentin/Projects/app/node_modules/pg/lib/connection.js:553:11)
at Connection.parseMessage (/home/valentin/Projects/app/node_modules/pg/lib/connection.js:378:19)
at TLSSocket.<anonymous> (/home/valentin/Projects/app/node_modules/pg/lib/connection.js:119:22)
at TLSSocket.emit (events.js:203:13)
at TLSSocket.EventEmitter.emit (domain.js:476:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:276:11)
at TLSSocket.Readable.push (_stream_readable.js:210:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:166:17) {
name: 'error',
length: 100,
severity: 'FATAL',
code: '28P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'auth.c',
line: '328',
routine: 'auth_failed'
}
Check the databaseUrl setting in the config.ts file.

What is this Mongoose CursorNotFound Error?

I have mongoose throwing this error from time to time, it's not stopping the node application from running but I can't find any information about whats causing the error and I would like to fix it.
The link to the repo is here https://github.com/bkawk/divergence2
I have found I can stop the error by adding a limit to the records here
https://github.com/bkawk/divergence2/blob/master/src/db.js#L94
{ MongoError: cursor id 31871209567 not found
at /Users/bkawk/Documents/divergence2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:598:61
at authenticateStragglers (/Users/bkawk/Documents/divergence2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:516:16)
at Connection.messageHandler (/Users/bkawk/Documents/divergence2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:552:5)
at emitMessageHandler (/Users/bkawk/Documents/divergence2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:309:10)
at Socket.<anonymous> (/Users/bkawk/Documents/divergence2/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:488:15)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:607:20)
name: 'MongoError',
message: 'cursor id 31871209567 not found',
ok: 0,
errmsg: 'cursor id 31871209567 not found',
code: 43,
codeName: 'CursorNotFound' }

Can't do basic find with Waterline in sails console

I have a Job model that searches a table of jobs. The table was created using rails, and I set 'migrate' to 'safe' in the Job model. I have written out all the attributes in the model. I cannot get basic functions to work in the sails console. I have three jobs in the table, with ids 1,2, and 3. When I execute:
sails> Job.findOneById(1).done(function(err,job){console.log(j.id)})
It poops out on me. The sails console crashes (super annoying). The output looks like this:
sails> Job.findOneById(1).done(function(err,job){console.log(j.id)})
undefined
sails>
/home/redmage/tac/node_modules/sails-postgresql/lib/query.js:544
var type = self._schema[key].type;
^
TypeError: Cannot read property 'type' of undefined
at /home/redmage/tac/node_modules/sails-postgresql/lib/query.js:544:33
at Array.forEach (native)
at Query.cast (/home/redmage/tac/node_modules/sails-postgresql/lib/query.js:541:23)
at /home/redmage/tac/node_modules/sails-postgresql/lib/adapter.js:372:32
at Array.forEach (native)
at __FIND__ (/home/redmage/tac/node_modules/sails-postgresql/lib/adapter.js:371:23)
at Query.handleReadyForQuery (/home/redmage/tac/node_modules/sails-postgresql/node_modules/pg/lib/query.js:84:10)
at null.<anonymous> (/home/redmage/tac/node_modules/sails-postgresql/node_modules/pg/lib/client.js:159:19)
at EventEmitter.emit (events.js:117:20)
at null.<anonymous> (/home/redmage/tac/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:97:12)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:528:21)
Here is the ORM for Job. It is very basic:
module.exports = {
//VERY IMPORTANT:
migrate: 'safe',
tableName: 'jobs',
attributes: {
}
}