Skip to content

Commit

Permalink
feat: add lambda lab on northwind
Browse files Browse the repository at this point in the history
#189
  • Loading branch information
FlavioLionelRita committed Nov 19, 2023
1 parent e405659 commit cf1dba5
Show file tree
Hide file tree
Showing 5 changed files with 549 additions and 29 deletions.
14 changes: 12 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
"version": "0.2.0",
"configurations": [
{
"name": "northwind",
"name": "lab string query",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/build/dev/labs/northwind/client/lab.js",
"program": "${workspaceFolder}/build/dev/labs/northwind/client/queryLab.js",
"envFile": "${workspaceFolder}/config/collections/workspace/.env"
},
{
"name": "lab lambda query",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/build/dev/labs/northwind/client/lambdaLab.js",
"envFile": "${workspaceFolder}/config/collections/workspace/.env"
}
]
Expand Down
22 changes: 22 additions & 0 deletions src/dev/labs/northwind/client/lambdaLab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ormClient } from '../../../../lib'
import { Orders } from './model'

async function execute () {
try {
ormClient.init('http://localhost:9291')
const query = (id:number)=> Orders.filter(p =>p.id==id)
.include(p=>[p.customer.map(p=>p.name),p.details
.include(p=>p.product
.include(p=>p.category.map(p=>p.name))
.map(p=>p.name))
.map(p=>[p.quantity,p.unitPrice])])
const data = {id: 10248 }
const sentence = await ormClient.sentence(query, { stage: 'default'})
console.log(JSON.stringify(sentence,null,2))
const result = await ormClient.execute(query, data,{ stage: 'default'})
console.log(JSON.stringify(result,null,2))
} catch (error: any) {
console.error(error)
}
}
execute()
219 changes: 219 additions & 0 deletions src/dev/labs/northwind/client/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/* eslint-disable no-use-before-define */
import { ManyToOne, OneToMany, Queryable } from '../../../../lib'
interface QryCategory {
id: number
name: string
description: string
}

interface QryCustomer {
id: string
name: string
contact: string
phone: string
address: string
city: string
region: string
postalCode: string
country: string
orders: ManyToOne<QryOrder>
}
interface QryEmployee {
id: number
lastName: string
firstName: string
title: string
titleOfCourtesy: string
birthDate: Date
hireDate: Date
phone: string
reportsToId: number
address: string
city: string
region: string
postalCode: string
country: string
reportsTo: QryEmployee & OneToMany<QryEmployee>
}
interface QryShipper {
id: number
name: string
phone: string
}
interface QrySupplier {
id: number
name: string
contact: string
phone: string
homepage: string
address: string
city: string
region: string
postalCode: string
country: string
}
interface QryProduct {
id: number
name: string
supplierId: number
categoryId: number
quantity: string
price: number
inStock: number
onOrder: number
reorderLevel: number
discontinued: boolean
supplier: QrySupplier & OneToMany<QrySupplier>
category: QryCategory & OneToMany<QryCategory>
}
interface QryOrder {
id: number
customerId: string
employeeId: number
orderDate: Date
requiredDate: Date
shippedDate: Date
shipViaId: number
freight: number
name: string
address: string
city: string
region: string
postalCode: string
country: string
customer: QryCustomer & OneToMany<QryCustomer>
employee: QryEmployee & OneToMany<QryEmployee>
details: ManyToOne<QryOrderDetail>
}
interface QryOrderDetail {
orderId: number
productId: number
unitPrice: number
quantity: number
discount: number
order: QryOrder & OneToMany<QryOrder>
product: QryProduct & OneToMany<QryProduct>
}

type QryCategories = Queryable<QryCategory>
type QryCustomers = Queryable<QryCustomer>
type QryEmployees = Queryable<QryEmployee>
type QryShippers = Queryable<QryShipper>
type QrySuppliers = Queryable<QrySupplier>
type QryProducts = Queryable<QryProduct>
type QryOrderDetails = Queryable<QryOrderDetail>
interface QryOrders extends Queryable<QryOrder>{
details: QryOrderDetails
}

export class Category {
id?: number
name?: string
description?: string
}

export class Customer {
constructor () {
this.orders = []
}

id?: string
name?: string
contact?: string
phone?: string
address?: string
city?: string
region?: string
postalCode?: string
country?: string
orders: Order[]
}
export class Employee {
id?: number
lastName?: string
firstName?: string
title?: string
titleOfCourtesy?: string
birthDate?: Date
hireDate?: Date
phone?: string
reportsToId?: number
address?: string
city?: string
region?: string
postalCode?: string
country?: string
reportsTo?: Employee
}
export class Shipper {
id?: number
name?: string
phone?: string
}
export class Supplier {
id?: number
name?: string
contact?: string
phone?: string
homepage?: string
address?: string
city?: string
region?: string
postalCode?: string
country?: string
}
export class Product {
id?: number
name?: string
supplierId?: number
categoryId?: number
quantity?: string
price?: number
inStock?: number
onOrder?: number
reorderLevel?: number
discontinued?: boolean
supplier?: Supplier
category?: Category
}
export class Order {
constructor () {
this.details = []
}

id?: number
customerId?: string
employeeId?: number
orderDate?: Date
requiredDate?: Date
shippedDate?: Date
shipViaId?: number
freight?: number
name?: string
address?: string
city?: string
region?: string
postalCode?: string
country?: string
customer?: Customer
employee?: Employee
details: OrderDetail[]
}
export class OrderDetail {
orderId?: number
productId?: number
unitPrice?: number
quantity?: number
discount?: number
order?: Order
product?: Product
}

export let Categories : QryCategories
export let Customers : QryCustomers
export let Employees :QryEmployees
export let Shippers : QryShippers
export let Suppliers : QrySuppliers
export let Products : QryProducts
export let OrderDetails : QryOrderDetails
export let Orders : QryOrders
File renamed without changes.

0 comments on commit cf1dba5

Please sign in to comment.