diff --git a/.gitignore b/.gitignore index 674425c..b5af964 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules npm-debug.log package-lock.json .vscode -coverage \ No newline at end of file +coverage +dist diff --git a/package.json b/package.json index 2965fa9..4cde7c3 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "drizzle": "tsx ./src/drizzle/benchmark-pg.ts", "orange": "tsx ./src/orange/benchmark-pg.ts", "prisma": "tsx ./src/prisma/benchmark-pg.ts", - "mikroorm": "tsx ./src/mikro-orm/benchmark-pg.ts", + "mikroorm": "node ./dist/mikro-orm/benchmark-pg.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", diff --git a/src/drizzle/benchmark-pg.ts b/src/drizzle/benchmark-pg.ts index d70bf86..4ccbf68 100644 --- a/src/drizzle/benchmark-pg.ts +++ b/src/drizzle/benchmark-pg.ts @@ -1,5 +1,5 @@ import { exit } from 'node:process'; -import postgres from './postgres' +import postgres from './postgres.js' import dotenv from 'dotenv'; dotenv.config();; const ITERATIONS = Number.parseInt(process.env.ITERATIONS); diff --git a/src/drizzle/postgres.ts b/src/drizzle/postgres.ts index d6753f2..4bfd712 100644 --- a/src/drizzle/postgres.ts +++ b/src/drizzle/postgres.ts @@ -1,6 +1,6 @@ import { drizzle } from 'drizzle-orm/postgres-js'; import postgres from "postgres"; -import * as schema from './schema'; +import * as schema from './schema.js'; export const connection = postgres('postgres://postgres:postgres@postgres/postgres', { max: 1 }); diff --git a/src/initPostgres.ts b/src/initPostgres.ts index c0f583c..0150b8b 100644 --- a/src/initPostgres.ts +++ b/src/initPostgres.ts @@ -1,7 +1,7 @@ import path from 'node:path'; import fs from 'node:fs'; const sql = fs.readFileSync(path.resolve("./data/init-postgres.sql"), "utf-8"); -import db from './orange/postgres'; +import db from './orange/postgres.js'; import { exit } from 'node:process'; diff --git a/src/mikro-orm/benchmark-pg.ts b/src/mikro-orm/benchmark-pg.ts index 0ff9cbe..c877067 100644 --- a/src/mikro-orm/benchmark-pg.ts +++ b/src/mikro-orm/benchmark-pg.ts @@ -2,12 +2,12 @@ import 'reflect-metadata'; import { MikroORM, ReflectMetadataProvider } from '@mikro-orm/core'; import { PostgreSqlDriver } from '@mikro-orm/postgresql'; import dotenv from 'dotenv'; -import { Customer } from './schema'; -import { Employee } from './schema'; -import { Order } from './schema'; -import { OrderDetail } from './schema'; -import { Product } from './schema'; -import { Supplier } from './schema'; +import { Customer } from './schema.js'; +import { Employee } from './schema.js'; +import { Order } from './schema.js'; +import { OrderDetail } from './schema.js'; +import { Product } from './schema.js'; +import { Supplier } from './schema.js'; dotenv.config(); const ITERATIONS = Number.parseInt(process.env.ITERATIONS); diff --git a/src/mikro-orm/schema.ts b/src/mikro-orm/schema.ts index 483aee0..1d3d674 100644 --- a/src/mikro-orm/schema.ts +++ b/src/mikro-orm/schema.ts @@ -1,40 +1,39 @@ -import { Entity, PrimaryKey, Property, ManyToOne, OneToMany, Collection, Index, EntityRepositoryType, Type } from '@mikro-orm/core'; -import { EntityRepository } from '@mikro-orm/postgresql'; +import { Entity, PrimaryKey, Property, ManyToOne, OneToMany, Collection, Index, Unique, type Rel } from '@mikro-orm/core'; @Entity({ tableName: 'customers' }) export class Customer { - @PrimaryKey({ name: 'id' }) - id: string; + @PrimaryKey({ fieldName: 'id' }) + id!: string; - @Property({ name: 'company_name' }) - companyName: string; + @Property({ fieldName: 'company_name' }) + companyName!: string; - @Property({ name: 'contact_name' }) - contactName: string; + @Property({ fieldName: 'contact_name' }) + contactName!: string; - @Property({ name: 'contact_title' }) - contactTitle: string; + @Property({ fieldName: 'contact_title' }) + contactTitle!: string; - @Property({ name: 'address' }) - address: string; + @Property({ fieldName: 'address' }) + address!: string; - @Property({ name: 'city' }) - city: string; + @Property({ fieldName: 'city' }) + city!: string; - @Property({ name: 'postal_code', nullable: true }) + @Property({ fieldName: 'postal_code', nullable: true }) postalCode?: string; - @Property({ name: 'region', nullable: true }) + @Property({ fieldName: 'region', nullable: true }) region?: string; - @Property({ name: 'country' }) - country: string; + @Property({ fieldName: 'country' }) + country!: string; - @Property({ name: 'phone' }) - phone: string; + @Property({ fieldName: 'phone' }) + phone!: string; - @Property({ name: 'fax', nullable: true }) + @Property({ fieldName: 'fax', nullable: true }) fax?: string; @OneToMany(() => Order, order => order.customer) @@ -42,78 +41,78 @@ export class Customer { } @Entity({ tableName: 'order_details' }) -@Index({ properties: ['orderId', 'productId'], unique: true }) +@Unique({ properties: ['orderId', 'productId'] }) export class OrderDetail { - @Property({ name: 'unit_price' }) - unitPrice: number; + @Property({ fieldName: 'unit_price' }) + unitPrice!: number; - @Property({ name: 'quantity' }) - quantity: number; + @Property({ fieldName: 'quantity' }) + quantity!: number; - @Property({ name: 'discount' }) - discount: number; + @Property({ fieldName: 'discount' }) + discount!: number; - @PrimaryKey({ name: 'order_id' }) - orderId: string; + @PrimaryKey({ fieldName: 'order_id', persist: false }) + orderId!: string; - @PrimaryKey({ name: 'product_id' }) - productId: string; + @PrimaryKey({ fieldName: 'product_id', persist: false }) + productId!: string; @ManyToOne(() => Order, { fieldName: 'order_id' }) - order: Order; + order!: Rel; @ManyToOne(() => Product, { fieldName: 'product_id' }) - product: Product; + product!: Rel; } @Entity({ tableName: 'employees' }) @Index({ properties: ['recipientId'] }) export class Employee { - @PrimaryKey({ name: 'id' }) - id: string; + @PrimaryKey({ fieldName: 'id' }) + id!: string; - @Property({ name: 'last_name' }) - lastName: string; + @Property({ fieldName: 'last_name' }) + lastName!: string; - @Property({ name: 'first_name', nullable: true }) + @Property({ fieldName: 'first_name', nullable: true }) firstName?: string; - @Property({ name: 'title' }) - title: string; + @Property({ fieldName: 'title' }) + title!: string; - @Property({ name: 'title_of_courtesy' }) - titleOfCourtesy: string; + @Property({ fieldName: 'title_of_courtesy' }) + titleOfCourtesy!: string; - @Property({ name: 'birth_date' }) - birthDate: Date; + @Property({ fieldName: 'birth_date' }) + birthDate!: Date; - @Property({ name: 'hire_date' }) - hireDate: Date; + @Property({ fieldName: 'hire_date' }) + hireDate!: Date; - @Property({ name: 'address' }) - address: string; + @Property({ fieldName: 'address' }) + address!: string; - @Property({ name: 'city' }) - city: string; + @Property({ fieldName: 'city' }) + city!: string; - @Property({ name: 'postal_code' }) - postalCode: string; + @Property({ fieldName: 'postal_code' }) + postalCode!: string; - @Property({ name: 'country' }) - country: string; + @Property({ fieldName: 'country' }) + country!: string; - @Property({ name: 'home_phone' }) - homePhone: string; + @Property({ fieldName: 'home_phone' }) + homePhone!: string; - @Property({ name: 'extension' }) - extension: number; + @Property({ fieldName: 'extension' }) + extension!: number; - @Property({ name: 'notes' }) - notes: string; + @Property({ fieldName: 'notes' }) + notes!: string; - @Property({ name: 'recipient_id', nullable: true }) + @Property({ fieldName: 'recipient_id', nullable: true }) recipientId?: string; @OneToMany(() => Order, order => order.employee) @@ -125,50 +124,50 @@ export class Employee { @Index({ properties: ['employeeId'] }) export class Order { - @PrimaryKey({ name: 'id' }) - id: string; + @PrimaryKey({ fieldName: 'id' }) + id!: string; - @Property({ name: 'order_date' }) - orderDate: Date; + @Property({ fieldName: 'order_date' }) + orderDate!: Date; - @Property({ name: 'required_date' }) - requiredDate: Date; + @Property({ fieldName: 'required_date' }) + requiredDate!: Date; - @Property({ name: 'shipped_date', nullable: true }) + @Property({ fieldName: 'shipped_date', nullable: true }) shippedDate?: Date; - @Property({ name: 'ship_via' }) - shipVia: number; + @Property({ fieldName: 'ship_via' }) + shipVia!: number; - @Property({ name: 'freight' }) - freight: number; + @Property({ fieldName: 'freight' }) + freight!: number; - @Property({ name: 'ship_name' }) - shipName: string; + @Property({ fieldName: 'ship_name' }) + shipName!: string; - @Property({ name: 'ship_city' }) - shipCity: string; + @Property({ fieldName: 'ship_city' }) + shipCity!: string; - @Property({ name: 'ship_region', nullable: true }) + @Property({ fieldName: 'ship_region', nullable: true }) shipRegion?: string; - @Property({ name: 'ship_postal_code', nullable: true }) + @Property({ fieldName: 'ship_postal_code', nullable: true }) shipPostalCode?: string; - @Property({ name: 'ship_country' }) - shipCountry: string; + @Property({ fieldName: 'ship_country' }) + shipCountry!: string; - @Property({ name: 'customer_id' }) - customerId: string; + @Property({ fieldName: 'customer_id', persist: false }) + customerId!: string; - @Property({ name: 'employee_id' }) - employeeId: string; + @Property({ fieldName: 'employee_id', persist: false }) + employeeId!: string; @ManyToOne(() => Customer, { fieldName: 'customer_id' }) - customer: Customer; + customer!: Rel; @ManyToOne(() => Employee, { fieldName: 'employee_id' }) - employee: Employee; + employee!: Rel; @OneToMany(() => OrderDetail, orderDetail => orderDetail.order) orderDetails = new Collection(this); @@ -178,35 +177,35 @@ export class Order { @Index({ properties: ['supplierId'] }) export class Product { - @PrimaryKey({ name: 'id' }) - id: string; + @PrimaryKey({ fieldName: 'id' }) + id!: string; - @Property({ name: 'name' }) - name: string; + @Property({ fieldName: 'name' }) + name!: string; - @Property({ name: 'qt_per_unit' }) - qtPerUnit: string; + @Property({ fieldName: 'qt_per_unit' }) + qtPerUnit!: string; - @Property({ name: 'unit_price' }) - unitPrice: number; + @Property({ fieldName: 'unit_price' }) + unitPrice!: number; - @Property({ name: 'units_in_stock' }) - unitsInStock: number; + @Property({ fieldName: 'units_in_stock' }) + unitsInStock!: number; - @Property({ name: 'units_on_order' }) - unitsOnOrder: number; + @Property({ fieldName: 'units_on_order' }) + unitsOnOrder!: number; - @Property({ name: 'reorder_level' }) - reorderLevel: number; + @Property({ fieldName: 'reorder_level' }) + reorderLevel!: number; - @Property({ name: 'discontinued' }) - discontinued: number; + @Property({ fieldName: 'discontinued' }) + discontinued!: number; - @Property({ name: 'supplier_id' }) - supplierId: string; + @Property({ fieldName: 'supplier_id', persist: false }) + supplierId!: string; @ManyToOne(() => Supplier, { fieldName: 'supplier_id' }) - supplier: Supplier; + supplier!: Rel; @OneToMany(() => OrderDetail, orderDetail => orderDetail.product) orderDetails = new Collection(this); @@ -215,35 +214,35 @@ export class Product { @Entity({ tableName: 'suppliers' }) export class Supplier { - @PrimaryKey({ name: 'id' }) - id: string; + @PrimaryKey({ fieldName: 'id' }) + id!: string; - @Property({ name: 'company_name' }) - companyName: string; + @Property({ fieldName: 'company_name' }) + companyName!: string; - @Property({ name: 'contact_name' }) - contactName: string; + @Property({ fieldName: 'contact_name' }) + contactName!: string; - @Property({ name: 'contact_title' }) - contactTitle: string; + @Property({ fieldName: 'contact_title' }) + contactTitle!: string; - @Property({ name: 'address' }) - address: string; + @Property({ fieldName: 'address' }) + address!: string; - @Property({ name: 'city' }) - city: string; + @Property({ fieldName: 'city' }) + city!: string; - @Property({ name: 'region', nullable: true }) + @Property({ fieldName: 'region', nullable: true }) region?: string; - @Property({ name: 'postal_code' }) - postalCode: string; + @Property({ fieldName: 'postal_code' }) + postalCode!: string; - @Property({ name: 'country' }) - country: string; + @Property({ fieldName: 'country' }) + country!: string; - @Property({ name: 'phone' }) - phone: string; + @Property({ fieldName: 'phone' }) + phone!: string; @OneToMany(() => Product, product => product.supplier) products = new Collection(this); diff --git a/src/orange/benchmark-pg.ts b/src/orange/benchmark-pg.ts index ad3f18b..380e88a 100644 --- a/src/orange/benchmark-pg.ts +++ b/src/orange/benchmark-pg.ts @@ -1,5 +1,5 @@ import { exit } from 'node:process'; -import pg from './postgres'; +import pg from './postgres.js'; import dotenv from 'dotenv'; dotenv.config();; const ITERATIONS = Number.parseInt(process.env.ITERATIONS); diff --git a/src/orange/postgres.ts b/src/orange/postgres.ts index f775b6a..f2c1c8b 100644 --- a/src/orange/postgres.ts +++ b/src/orange/postgres.ts @@ -1,4 +1,4 @@ -import map from './map'; +import map from './map.js'; export default map.postgres('postgres://postgres:postgres@postgres/postgres', { size: 1}); diff --git a/tsconfig.json b/tsconfig.json index 1462942..2fca784 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,8 @@ "target": "ESNext", "esModuleInterop": true, "strict": true, - "moduleResolution": "node", - "noEmit": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", "outDir": "dist", "forceConsistentCasingInFileNames": true, "skipLibCheck": true,