Questions tagged [mikro-orm]
MikroORM is TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Currently it supports MongoDB, MySQL, PostgreSQL and SQLite databases. It has first class TypeScript support, while staying back compatible with Vanilla JavaScript.
mikro-orm
222
questions
0
votes
1
answer
29
views
MikroORM CLI Error: No database specified, please fill in `dbName` or `clientUrl` option
Trying to get the MikroORM CLI running, but no luck.
I have NX monorepo with MikroORM being a library.
I have tried with .env variables and with package.json but getting different errors for them.
...
0
votes
1
answer
39
views
+50
How to provide fresh instance of Mikro ORM entity manager into repositories during testing?
I am trying to test my command handler which has multiple repositories injected into it. When running the test I am getting the following error:
ValidationError: Using global EntityManager instance ...
0
votes
1
answer
43
views
Mikro-orm: Update with select statement
I am trying to update a table column that is dependent on one more table. The sql query is working fine on database and couldn't figure out the mikro-orm query for that. Below are the sql and mikro-...
0
votes
0
answers
20
views
How to properly unit test a class with Mikro ORM and NestJS?
I have a service called PackageCalculator
@Injectable()
export class PackageCalculator {
private readonly logger = new Logger(PackageCalculator.name);
private doesPackagesMatch(packageDosages: ...
0
votes
1
answer
99
views
Cannot run Mikro-ORM migrations on bun
I'm currently running an all-typescript project with Bun + Elysia. I've migrated my app from a previous NestJs project, which was running MikroORM just fine. Now that I've had my app running via bun, ...
0
votes
0
answers
35
views
Mikro ORM migration error: The "path" argument must be of type string. Received undefined
I'm trying to set up an integration test and need to migrate the db to the latest but got this error:
const orm = await MikroORM.init(options);
await orm.getMigrator().up(); // this line cause the ...
0
votes
0
answers
23
views
adminJS shows raw IDs instead of actual data (using mikroORM and postreSQL)
I am using TypeScript, mikroORM, postreSQL and adminJS. Trying to achieve the actual data being displayed instead of its raw IDs. I have two entities:
@Entity({ tableName: 'professors' })
export class ...
0
votes
0
answers
13
views
Should MikroORM be injected into a builder class or should it be integrated into a repository for the same service?
I have a builder class which I simplified below:
interface Builder {
setTitle(title: string): BookBuilder;
... // sets a bunch of attributes here
build(): Book;
}
class BookBuilder ...
-1
votes
1
answer
43
views
Issue while saving time without timezone in PostgreSQL
I'm encountering an issue when trying to insert a time value into a field defined as startTime in my entity in PostgreSQL. Here's the relevant code:
@Property({ type: 'time' })
startTime!: Date;
And ...
1
vote
1
answer
46
views
Mikro Orm v6 .raw function doesnt exist in createQueryBuilder
I am having an issue with the upgrade to mikrOrm v6 and cannot find any documentation on what I can do to upgrade. I keep getting an error for qb.raw doesnt exist on createquerybuilder. Is there an ...
0
votes
0
answers
35
views
Type 'E' does not satisfy the constraint 'object'
This error is throwing after upgrade the node version to 20. In node version 16 it was work perfectly
error TS2345: Argument of type 'E' is not assignable to parameter of type 'Partial | Partial[]'.
...
0
votes
1
answer
112
views
mikroorm postgresql setup error with type
So i'm trying to setup a mikroorm with postgresql, but I get this weird error on the type:
This is the code
import { MikroORM, Options} from "@mikro-orm/core";
import { _prod_ } from "./...
-1
votes
1
answer
40
views
How do I import a type definition from a module in JavaScript+JSDoc?
I am trying to import a type definition from a module in JSDoc into my SvelteKit application.
This is the TypeScript code I'm trying to implement as JS/JSDoc:
import type { PostgreSqlDriver } from '@...
0
votes
0
answers
71
views
MikroORM update coallesce
In MikroORM, what would be the best/efficient way to implement update for specific values that are NOT NULL? For example, in Postgres there is the COALESCE() function:
UPDATE some_table SET ...
1
vote
1
answer
182
views
How to run E2E testings with Nest.js and MikroORM?
So, I have this Nest.js API app that use SWC and Vitest. Here are the minimized files of Users module.
CRUD users service:
// users.service.ts
...
@Injectable()
@UseInterceptors(...
1
vote
1
answer
127
views
Nestjs with MikroOrm can't inject Entity Manager
I'm using an nx monorepo with NestJS and MikroORM.
I've create a module called PersistanceModule that is defined like this:
import { Module } from '@nestjs/common';
import { MikroOrmModule } ...
1
vote
1
answer
73
views
MikroORM - Non-FK'd ID conditional join
I have inherited this strange database schema, where there's a jsonb field, and on that json is a userId, and userType. There are also two user tables, representing different user types. The table ...
0
votes
1
answer
64
views
How to only discover said entities instead all?
I'm using Mikro-orm (6.1.5) in serverless functions with a shared db package where I keep all my entities. Since the app started to get bigger I noticed a slow down and realised all my entities were ...
0
votes
0
answers
26
views
MIKRO ORM: Load only the nested entities that fit the criteria
I have a series of nested entities that works like that:
queryBuilder
.select(`*`)
.joinAndSelect('project.segments', 's1', undefined, 'innerJoin')
.joinAndSelect('s1....
-1
votes
1
answer
27
views
How to order the query through the greatest updatedAt on a nested one to many entity
I have a series of nested entities that works like that:
Entity1 -> Entity2 -> Entity3 ( With arrows representing a one to many relationship)
Im using MikroORM.
How can i write a findAndCount ...
0
votes
0
answers
238
views
in mikroorm when I try to insert record it do update statement
I am try to use mikroorm with nest js
import { Migrator } from '@mikro-orm/migrations';
import { defineConfig } from '@mikro-orm/postgresql';
import { TsMorphMetadataProvider } from '@mikro-orm/...
0
votes
0
answers
121
views
Get all entities where the string array property contains the input string (MikroOrm + TypeScript)
I'm trying to make a MikroOrm query in Typescript that gets all Movies which belong to a specified inputGenre. Each Movie has not one, but an array of genres associated to it. So if I have the ...
2
votes
0
answers
139
views
MikroORM cannot find module using absolute paths for importing
I am using NestJS with TypeScript and MikroORM with the MikroOrm-configuration
{
...
entities: ['dist/db/entities'],
entitiesTs: ['src/db/entities'],
baseDir: process.cwd() // default ...
0
votes
1
answer
76
views
Mikro-ORM nested collection type safe access
I am unable to access properties of a nested loaded entities. I have the following structure
Treatment OneToMany TreatmentCycle
TreatmentCycle ManyToOne Physician
Physician ManyToOne User
User ...
0
votes
1
answer
102
views
How to define an array in Mikro-ORM abstract base entity?
I am trying have an array with domain events in my Mikro-ORM abstract entity, but after retrieving the entity from persistence (repository) it is undefined. Is there a way to make it initialized after ...
0
votes
1
answer
166
views
MikroORM referenced entity JSON value
I don't know if this is a bug or correct behavior, but when I return json from an entity that has a reference Ref to @ManyToOne entity I get "city": "bd612c71" for that reference, ...
1
vote
1
answer
283
views
How to properly use MirkoORM custom repository with NestJS?
When registering entities through MirkoORM.forFeature() method it automatically registers the repositories if I have the entity properly set up.
This is an example entity I have
@Entity({
...
0
votes
1
answer
214
views
How to extend custom BaseRepository with Mikro ORM EntityRepository
I am trying to create a BaseRepository with custom methods that every repository should have. I have created my custom repository and extended it with EntityRepository but I get TS warning when trying ...
0
votes
1
answer
254
views
I can't read env values in mikro-orm.config.ts
I use mikro-orm in nest js, and i write mikro-orm.config.ts with using configService.get().
But it doesn't get env value. Process.env is too.
In other files like main.ts, it can get env properly, but ...
0
votes
1
answer
134
views
Nestjs Mirko-orm through exception with no trace
Im stuck trying to identify where this error is in my nestjs application. Anyone have any ideas or options I can add to get more info?
[Nest] 8792 - 06/10/2023, 3:32:29 pm ERROR [...
0
votes
0
answers
178
views
Mikro-ORM Keeps Generating Unwanted Migrations for text[] Column Type in NestJS
I'm using NestJS along with Mikro-ORM and PostgreSQL for my project. I've run into an issue where Mikro-ORM continuously generates migration changes for certain fields even when there are no changes ...
0
votes
1
answer
615
views
MikroORM jest unit test - how to provide entity repository with connect: false
When I use MikroORM.init() in unit test I want to use connect:false option to not create db connection, but test the entity behaviour for example more complex update method like: "wrap(...
0
votes
0
answers
416
views
How to Properly Select Specific Fields in Mikro-ORM for MongoDB to Avoid Circular References?
I'm using NestJS with Fastify and Mikro-ORM (for MongoDB) and I'm facing an issue related to circular references when trying to serialize my entities. Here are simplified versions of my primary ...
1
vote
1
answer
425
views
Common Table Expressions - is there a way to do them in MikroOrm?
Is there a way (even a hacky way) to do common table expressions with MikroOrm? I've searched all over and can't even find any post mentioning it whatsoever.
0
votes
1
answer
198
views
In mikro-orm, Is it possible to track unit of work changes in the afterTransactionCommit hook in explicit transactions?
In afterFlush event we receive the changes in entities seeing uow arg:
async afterFlush(args: FlushEventArgs): Promise<void> {
args.uow?.getChangeSets()...
But in afterTransactionCommit ...
0
votes
0
answers
211
views
Can I tell mikro to add a trigger to a table?
I would like to put a trigger on a database table to create a log entry every time one of the columns changes. Roughly:
create function update_status_log() returns trigger as $update_status_log$
...
0
votes
0
answers
241
views
MikroORM: "must appear in the GROUP BY clause or be used in an aggregate function"
I have the following query set up using the QueryBuilder:
return this.qb('user')
.where({ id })
.leftJoin('user.transactions', 'transactions')
.leftJoin('user.wallet', 'wallet')
...
0
votes
0
answers
40
views
SQL aggregation with GROUP_BY where in custom field should be saved value from field 'amount' only for last created transaction item in aggregation
I have the list of merchants, this entity is global. For certain users, I should aggregate a list of merchants by their own transactions which have relation to merchant_id, merchants should be ordered ...
0
votes
0
answers
133
views
MySQL server log swarms with "Aborted connection (...) (Got an error reading communication packets)" when using Mikro-ORM/Knex
I'm using MikroORM v5.7.10 with Knex v2.4.2.
There is a connection pool that looks like: {min: 0, max: 10}.
From the application point of view, everything seems to be fine - no errors related to ...
0
votes
1
answer
163
views
Collection<CaseItem> of entity CsgoItem[] not initialized when fetching count
I have the following entity set up:
@Entity()
export class CsgoItem extends CommonBaseEntity {
@Property()
name: string;
@Property({ nullable: true })
condition: string;
@Property({ ...
0
votes
0
answers
191
views
docker container exec mikro-orm migration wont exit after success
I have an ecs container that im running for my mikro-orm migrations. I need this container to exit after success for the task to stop running.
I have tried numerous different approaches such as:
"...
2
votes
1
answer
446
views
Why is Mikro-orm sending back numbers as strings?
I have a postCount property on a User entity that looks like this:
@Property({columnType: 'bigint', nullable: false, default: 0})
postsCount: number;
I expect it to come back as a number, but it ...
0
votes
1
answer
527
views
How to insert into a table the result of a select query with mikro-orm
I make a project with postgresql and I use mikro-orm to work with it.
There is a table of the following structure:
id | foreign_id | created_at
---+------------+-----------
1 | 2 | 2023-05-...
-1
votes
1
answer
422
views
Mikro ORM unique decorator is not being enforced when
Using this entity:
@Entity()
@Unique({ properties: ['case', 'csgoItem'] })
export class CaseItem {
@PrimaryKey({ type: 'uuid', defaultRaw: 'uuid_generate_v4()' })
id: string;
@Property({ type: '...
0
votes
1
answer
271
views
MikroORM: No Update Event Fired When Adding an Entity to a Collection
In MikroORM, I have two entities, let's call them Entity A and Entity B, set up with a one-to-many relationship. Entity A has a Collection of Entity B instances. I'm using an event subscriber to ...
0
votes
0
answers
229
views
Mikro ORM Virtual entity not being present in service
I have the following NestJS route set up:
@Get(':id')
async getUserInfo(@Param('id') id: string) {
const res = await this.userService.findOneByField(id);
console.log(res);
return res;
...
0
votes
1
answer
502
views
Mikro-ORM w/MongoDB does not detect changes to arrays or insert new values
The problem I'm facing is that Mikro-ORM doesn't seem to detect array changes or be able to insert values into arrays. For example when inserting a number into a numbers array. I'm using MongoDB which ...
0
votes
1
answer
349
views
Mikro ORM validation errors not catched
I have the following function:
@SubscribeMessage('sendMessage')
async handleSendMessage(
_: Socket,
payload: CreateMessageInput,
): Promise<void> {
try {
const created = ...
1
vote
0
answers
286
views
Generic EntityById pipe nest js
I'm Trying to Implement a Generic EntityById Pipe Similar to the one From the Nest.js Documentation's Pipe Transformation UseCase UserByIdPipe, for that I can implement this simply like this
@...
0
votes
1
answer
48
views
Why cant I install @mikro-orm/mariadb
Trying to install mikroorm into adminjs. I am using:https://mikro-orm.io/docs/usage-with-adminjs
I ran the command npm install @mikro-orm/mariadb as instructed in the guide and it returns
npm ERR! ...