Skip to content

Commit

Permalink
mssql todo mikro
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Erik Roald committed Jul 19, 2024
1 parent 905f662 commit c8bfd41
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 41 deletions.
5 changes: 3 additions & 2 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
build:
context: .
dockerfile: Dockerfile
command: /bin/sh -c "sed -i 's/localhost:15432/postgres/g' /workspace/.env && sed -i 's/mysql on localhost:13306/mysql/g' /workspace/.env && sleep infinity"
command: /bin/sh -c "sed -i 's/localhost:15432/postgres/g' /workspace/.env && sed -i 's/localhost:13306/mysql/g' /workspace/.env && sed -i 's/localhost:13306/mssql/g' /workspace/.env && sleep infinity"
volumes:
- ..:/workspace:cached
- try-node-node_modules:/workspace/node_modules
Expand All @@ -19,10 +19,11 @@ services:
# ports:
# - 15432:5432
mssql:
image: mcr.microsoft.com/mssql/server:2019-latest
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=P@assword123
- MSSQL_SA_PASSWORD=P@assword123
ports:
- 14330:1433
# mysql:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: sed -i 's/localhost:15432/postgres/g' .env
- run: sed -i 's/localhost:13306/mysql/g' .env
- run: sed -i 's/localhost,14330/mssql/g' .env
- run: npm install
- run: npm run benchmark
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ The CPU had 4 physical cores, and each core supports 2 threads, making a total o
| Prisma | 49.419 s | 33.730 s |
| Mikro | 2:05.736 min | 1:58.967 min|

**SQL Server**
| | Pool size = 1 | Pool size = 10 |
|--------|---------------|----------------|
| Orange | 2:31.942 min | 1:11.334s s |
| Drizzle| N/A | N/A |
| Prisma | 1:30.985 min s | 38.529 s |
| Mikro | min | console.dir(rows, {depth: Infinity});
min|
**MySQL**
| | Pool size = 1 | Pool size = 10 |
|--------|---------------|----------------|
Expand Down
72 changes: 36 additions & 36 deletions data/init-mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ DROP TABLE if exists employees;
-- Create customers table
CREATE TABLE customers (
id VARCHAR(10) PRIMARY KEY NOT NULL,
company_name NVARCHAR(MAX) NOT NULL,
contact_name NVARCHAR(MAX) NOT NULL,
contact_title NVARCHAR(MAX) NOT NULL,
address NVARCHAR(MAX) NOT NULL,
city NVARCHAR(MAX) NOT NULL,
postal_code NVARCHAR(MAX),
region NVARCHAR(MAX),
country NVARCHAR(MAX) NOT NULL,
phone NVARCHAR(MAX) NOT NULL,
fax NVARCHAR(MAX)
company_name VARCHAR(50) NOT NULL,
contact_name VARCHAR(50) NOT NULL,
contact_title VARCHAR(50) NOT NULL,
address VARCHAR(50) NOT NULL,
city VARCHAR(50) NOT NULL,
postal_code VARCHAR(50),
region VARCHAR(50),
country VARCHAR(50) NOT NULL,
phone VARCHAR(50) NOT NULL,
fax VARCHAR(50)
);

-- Create order_details table
Expand All @@ -33,19 +33,19 @@ CREATE TABLE order_details (
-- Create employees table
CREATE TABLE employees (
id VARCHAR(10) PRIMARY KEY NOT NULL,
last_name NVARCHAR(MAX) NOT NULL,
first_name NVARCHAR(MAX),
title NVARCHAR(MAX) NOT NULL,
title_of_courtesy NVARCHAR(MAX) NOT NULL,
last_name VARCHAR(50) NOT NULL,
first_name VARCHAR(50),
title VARCHAR(50) NOT NULL,
title_of_courtesy VARCHAR(50) NOT NULL,
birth_date DATE NOT NULL,
hire_date DATE NOT NULL,
address NVARCHAR(MAX) NOT NULL,
city NVARCHAR(MAX) NOT NULL,
postal_code NVARCHAR(MAX) NOT NULL,
country NVARCHAR(MAX) NOT NULL,
home_phone NVARCHAR(MAX) NOT NULL,
address VARCHAR(50) NOT NULL,
city VARCHAR(50) NOT NULL,
postal_code VARCHAR(50) NOT NULL,
country VARCHAR(50) NOT NULL,
home_phone VARCHAR(50) NOT NULL,
extension INT NOT NULL,
notes NVARCHAR(MAX) NOT NULL,
notes VARCHAR(500) NOT NULL,
recipient_id VARCHAR(10)
);

Expand All @@ -57,20 +57,20 @@ CREATE TABLE orders (
shipped_date DATE,
ship_via INT NOT NULL,
freight FLOAT NOT NULL,
ship_name NVARCHAR(MAX) NOT NULL,
ship_city NVARCHAR(MAX) NOT NULL,
ship_region NVARCHAR(MAX),
ship_postal_code NVARCHAR(MAX),
ship_country NVARCHAR(MAX) NOT NULL,
ship_name VARCHAR(50) NOT NULL,
ship_city VARCHAR(50) NOT NULL,
ship_region VARCHAR(50),
ship_postal_code VARCHAR(50),
ship_country VARCHAR(50) NOT NULL,
customer_id VARCHAR(10) NOT NULL,
employee_id VARCHAR(10) NOT NULL
);

-- Create products table
CREATE TABLE products (
id VARCHAR(10) PRIMARY KEY NOT NULL,
name NVARCHAR(MAX) NOT NULL,
qt_per_unit NVARCHAR(MAX) NOT NULL,
name VARCHAR(50) NOT NULL,
qt_per_unit VARCHAR(50) NOT NULL,
unit_price FLOAT NOT NULL,
units_in_stock INT NOT NULL,
units_on_order INT NOT NULL,
Expand All @@ -82,15 +82,15 @@ CREATE TABLE products (
-- Create suppliers table
CREATE TABLE suppliers (
id VARCHAR(10) PRIMARY KEY NOT NULL,
company_name NVARCHAR(MAX) NOT NULL,
contact_name NVARCHAR(MAX) NOT NULL,
contact_title NVARCHAR(MAX) NOT NULL,
address NVARCHAR(MAX) NOT NULL,
city NVARCHAR(MAX) NOT NULL,
region NVARCHAR(MAX),
postal_code NVARCHAR(MAX) NOT NULL,
country NVARCHAR(MAX) NOT NULL,
phone NVARCHAR(MAX) NOT NULL
company_name VARCHAR(50) NOT NULL,
contact_name VARCHAR(50) NOT NULL,
contact_title VARCHAR(50) NOT NULL,
address VARCHAR(50) NOT NULL,
city VARCHAR(50) NOT NULL,
region VARCHAR(50),
postal_code VARCHAR(50) NOT NULL,
country VARCHAR(50) NOT NULL,
phone VARCHAR(50) NOT NULL
);

-- Create indexes
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
"orange:pool1:pg": "npm run init:pg && cross-env POOLSIZE=1 tsx ./src/orange/benchmark-pg.ts",
"orange:pool10:pg": "npm run init:pg && cross-env POOLSIZE=10 tsx ./src/orange/benchmark-pg.ts",
"prisma": "npm run prisma:mysql && npm run prisma:pg && npm run prisma:sqlite",
"prisma:mssql": "npm run init:mssql && prisma generate --schema=./src/prisma/schema-mssql.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-mssql.ts && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-mssql.ts",
"prisma:sqlite": "npm run init:sqlite && prisma generate --schema=./src/prisma/schema-sqlite.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-sqlite.ts && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-sqlite.ts",
"prisma:mysql": "npm run init:mysql && prisma generate --schema=./src/prisma/schema-mysql.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-mysql.ts && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-mysql.ts",
"prisma:pg": "npm run init:pg && prisma generate --schema=./src/prisma/schema-pg.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-pg.ts && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-pg.ts",
"prisma:pool1:mssql": "npm run init:mssql && prisma generate --schema=./src/prisma/schema-mssql.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-mssql.ts",
"prisma:pool10:mssql": "npm run init:mssql && prisma generate --schema=./src/prisma/schema-mssql.prisma && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-mssql.ts",
"prisma:pool1:sqlite": "npm run init:sqlite && prisma generate --schema=./src/prisma/schema-sqlite.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-sqlite.ts",
"prisma:pool10:sqlite": "npm run init:sqlite && prisma generate --schema=./src/prisma/schema-sqlite.prisma && cross-env POOLSIZE=10 tsx ./src/prisma/benchmark-sqlite.ts",
"prisma:pool1:mysql": "npm run init:mysql && prisma generate --schema=./src/prisma/schema-mysql.prisma && cross-env POOLSIZE=1 tsx ./src/prisma/benchmark-mysql.ts",
Expand Down
3 changes: 1 addition & 2 deletions src/orange/mssql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ dotenv.config();

const POOLSIZE = Number.parseInt(process.env.POOLSIZE);

export default map.mssql(process.env.MSSQL_URL, { size: POOLSIZE});

export default map.mssql(process.env.MSSQL_URL, { size: POOLSIZE });
6 changes: 5 additions & 1 deletion src/prisma/benchmark-mssql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ const LOG = process.env.LOG === 'true';
const prisma = new PrismaClient({
datasources: {
db: {
url: `${process.env.MSSQL_URL}?connection_limit=${POOLSIZE}`,
// url: `sqlserver://sa:P40assword123@localhost:14330/master?connection_limit=0`,
url: `sqlserver://mssql;initial catalog=master;user=sa;password=P@assword123;trustServerCertificate=true;encrypt=false;connectionLimit=${POOLSIZE};poolTimeout=20`,

// url: `${process.env.MSSQL_URL.replace('server=', 'sqlserver://')}?connection_limit=${POOLSIZE}`,
},
},

log: LOG ? [{ emit: 'event', level: 'query' }] : undefined
});

Expand Down
119 changes: 119 additions & 0 deletions src/prisma/schema-mssql.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlserver"
url = env("MSSQL_URL")
}

model Customer {
id String @id @map("id")
companyName String @map("company_name")
contactName String @map("contact_name")
contactTitle String @map("contact_title")
address String @map("address")
city String @map("city")
postalCode String? @map("postal_code")
region String? @map("region")
country String @map("country")
phone String @map("phone")
fax String? @map("fax")
orders Order[]
@@map("customers")
}

model OrderDetail {
unitPrice Float @map("unit_price")
quantity Int @map("quantity")
discount Float @map("discount")
orderId String @map("order_id")
productId String @map("product_id")
order Order @relation(fields: [orderId], references: [id])
product Product @relation(fields: [productId], references: [id])
@@id([orderId, productId])
@@map("order_details")
}

model Employee {
id String @id @map("id")
lastName String @map("last_name")
firstName String? @map("first_name")
title String @map("title")
titleOfCourtesy String @map("title_of_courtesy")
birthDate DateTime @map("birth_date")
hireDate DateTime @map("hire_date")
address String @map("address")
city String @map("city")
postalCode String @map("postal_code")
country String @map("country")
homePhone String @map("home_phone")
extension Int @map("extension")
notes String @map("notes")
recipientId String? @map("recipient_id")
orders Order[]
@@index([recipientId])
@@map("employees")
}

model Order {
id String @id @map("id")
orderDate DateTime @map("order_date")
requiredDate DateTime @map("required_date")
shippedDate DateTime? @map("shipped_date")
shipVia Int @map("ship_via")
freight Float @map("freight")
shipName String @map("ship_name")
shipCity String @map("ship_city")
shipRegion String? @map("ship_region")
shipPostalCode String? @map("ship_postal_code")
shipCountry String @map("ship_country")
customerId String @map("customer_id")
employeeId String @map("employee_id")
customer Customer @relation(fields: [customerId], references: [id])
employee Employee @relation(fields: [employeeId], references: [id])
orderDetails OrderDetail[]
@@index([customerId])
@@index([employeeId])
@@map("orders")
}

model Product {
id String @id @map("id")
name String @map("name")
qtPerUnit String @map("qt_per_unit")
unitPrice Float @map("unit_price")
unitsInStock Int @map("units_in_stock")
unitsOnOrder Int @map("units_on_order")
reorderLevel Int @map("reorder_level")
discontinued Int @map("discontinued")
supplierId String @map("supplier_id")
supplier Supplier @relation(fields: [supplierId], references: [id])
orderDetails OrderDetail[]
@@index([supplierId])
@@map("products")
}

model Supplier {
id String @id @map("id")
companyName String @map("company_name")
contactName String @map("contact_name")
contactTitle String @map("contact_title")
address String @map("address")
city String @map("city")
region String? @map("region")
postalCode String @map("postal_code")
country String @map("country")
phone String @map("phone")
products Product[]
@@map("suppliers")
}

0 comments on commit c8bfd41

Please sign in to comment.