Skip to content

Commit

Permalink
feat: update for changes on service
Browse files Browse the repository at this point in the history
#189
  • Loading branch information
FlavioLionelRita committed Nov 17, 2023
1 parent 756eb82 commit 7c52331
Show file tree
Hide file tree
Showing 9 changed files with 31,125 additions and 6 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "northwind",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/build/dev/labs/northwind/client/lab.js",
"envFile": "${workspaceFolder}/config/collections/workspace/.env"
}
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
"gmail",
"gruntfile",
"lambdaorm",
"MYSQL",
"northwind",
"npmjs",
"openapi",
"openapitools"
"openapitools",
"pnorthwind"
]
}
2 changes: 0 additions & 2 deletions src/dev/config/lambda-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ externalDocs:
servers:
- description: localhost
url: "http://localhost:9291"
- description: docker-local
url: "http://0.0.0.0:9291"
tags:
- description: Expression methods
name: expression
Expand Down
6 changes: 3 additions & 3 deletions src/dev/labs/lab.ts → src/dev/labs/northwind/client/lab.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ormClient } from '../../lib'
import { ormClient } from '../../../../lib'

async function execute () {
try {
ormClient.init('http://localhost:9291')
const query = 'PmIndividuals.filter(p=> p.gender == gender).include(p->p.party)'
const data = { "gender": "F" }
const query = '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 result = await ormClient.execute(query, data,{ stage: 'default'})
console.log(JSON.stringify(result,null,2))
const sentence = await ormClient.sentence(query, { stage: 'default'})
Expand Down
243 changes: 243 additions & 0 deletions src/dev/labs/northwind/service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
# Northwind lab

## Start

```sh
docker-compose -p lambdaorm-svc up -d
mysql -h 0.0.0.0 -P 3306 -u northwind -pnorthwind northwind < northwind-mysql.sql
```

## Test

**Model:**

```sh
curl -X POST "http://localhost:9291/model?format=beautiful" -H "Content-Type: application/json" -d '{"expression": "Orders.filter(p=>p.id==id).include(p=>p.details)"}'
```

Result:

```json
[
{
"name": "id",
"type": "integer"
},
{
"name": "customerId",
"type": "string"
},
{
"name": "employeeId",
"type": "integer"
},
{
"name": "orderDate",
"type": "dateTime"
},
{
"name": "requiredDate",
"type": "date"
},
{
"name": "shippedDate",
"type": "date"
},
{
"name": "shipViaId",
"type": "integer"
},
{
"name": "freight",
"type": "decimal"
},
{
"name": "name",
"type": "string"
},
{
"name": "address",
"type": "string"
},
{
"name": "city",
"type": "string"
},
{
"name": "region",
"type": "string"
},
{
"name": "postalCode",
"type": "string"
},
{
"name": "country",
"type": "string"
},
{
"name": "details",
"type": "Orders.details[]",
"children": [
{
"name": "orderId",
"type": "integer"
},
{
"name": "productId",
"type": "integer"
},
{
"name": "unitPrice",
"type": "decimal"
},
{
"name": "quantity",
"type": "decimal"
},
{
"name": "discount",
"type": "decimal"
},
{
"name": "LambdaOrmParentId",
"type": "integer"
}
]
}
]
```

**Parameters:**

```sh
curl -X POST "http://localhost:9291/parameters?format=beautiful" -H "Content-Type: application/json" -d '{"expression": "Orders.filter(p=>p.id==id).include(p=>p.details)"}'
```

Result:

```json
[
{
"name": "id",
"type": "integer"
},
{
"name": "details",
"type": "Orders.details",
"children": [
{
"name": "LambdaOrmParentId",
"type": "any"
}
]
}
]
```

**Constraints:**

```sh
curl -X POST "http://localhost:9291/constraints?format=beautiful" -H "Content-Type: application/json" -d '{"expression": "Orders.filter(p=>p.id==id).include(p=>p.details)"}'
```

Result:

```json
{
"entity": "Orders",
"constraints": [],
"children": [
{
"entity": "Orders.details",
"constraints": []
}
]
}
```

**Sentence:**

```sh
curl -X POST "http://localhost:9291/sentence?format=beautiful" -H "Content-Type: application/json" -d '{"expression": "Orders.filter(p=>p.id==id).include(p=>p.details)"}'
```

Result:

```json
{
"entity": "Orders",
"dialect": "MySQL",
"source": "default",
"sentence": "SELECT o.OrderID AS id, o.CustomerID AS customerId, o.EmployeeID AS employeeId, o.OrderDate AS orderDate, o.RequiredDate AS requiredDate, o.ShippedDate AS shippedDate, o.ShipVia AS shipViaId, o.Freight AS freight, o.ShipName AS name, o.ShipAddress AS address, o.ShipCity AS city, o.ShipRegion AS region, o.ShipPostalCode AS postalCode, o.ShipCountry AS country, o.OrderID AS `__id` FROM Orders o WHERE o.OrderID = ? ",
"children": [
{
"entity": "Orders.details",
"dialect": "MySQL",
"source": "default",
"sentence": "SELECT o1.OrderID AS orderId, o1.ProductID AS productId, o1.UnitPrice AS unitPrice, o1.Quantity AS quantity, o1.Discount AS discount, o1.OrderID AS LambdaOrmParentId FROM `Order Details` o1 WHERE o1.OrderID IN (?) ",
"children": []
}
]
}
```

**Execute:**

```sh
curl -X POST "http://localhost:9291/execute?format=beautiful" -H "Content-Type: application/json" -d '{"expression": "Orders.filter(p=>p.id==id).include(p=>p.details)", "data": "{\"id\": 10248}" }'
```

Result:

```json
[
{
"id": 10248,
"customerId": "VINET",
"employeeId": 5,
"orderDate": "1996-07-04T00:00:00.000Z",
"requiredDate": "1996-08-01T00:00:00.000Z",
"shippedDate": "1996-07-16T00:00:00.000Z",
"shipViaId": 3,
"freight": 32.38,
"name": "Vins et alcools Chevalier",
"address": "59 rue de l-Abbaye",
"city": "Reims",
"region": null,
"postalCode": "51100",
"country": "France",
"details": [
{
"orderId": 10248,
"productId": 11,
"unitPrice": 14,
"quantity": 12,
"discount": 0
},
{
"orderId": 10248,
"productId": 42,
"unitPrice": 9.8,
"quantity": 10,
"discount": 0
},
{
"orderId": 10248,
"productId": 72,
"unitPrice": 34.8,
"quantity": 5,
"discount": 0
}
]
}
]
```

## End

```sh
docker-compose -p lambdaorm-svc down --remove-orphans
docker volume rm lambdaorm-svc_mysql-data
docker volume rm lambdaorm-svc_mysql-log
```
48 changes: 48 additions & 0 deletions src/dev/labs/northwind/service/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3.2"
networks:
northwind:
driver: bridge
services:
mysql:
container_name: mysql
image: mysql:5.7
restart: always
environment:
- MYSQL_DATABASE=northwind
- MYSQL_USER=northwind
- MYSQL_PASSWORD=northwind
- MYSQL_ROOT_PASSWORD=northwind
ports:
- '3306:3306'
expose:
- 3306
networks:
- northwind
volumes:
- mysql-data:/var/lib/mysql
- mysql-log:/var/log/mysql
orm:
depends_on:
- mysql
container_name: orm
image: flaviorita/lambdaorm-svc:0.8.43
restart: always
environment:
HOST: http://0.0.0.0
PORT: 9291
REQUEST_BODY_SIZE: 100mb
RATE_LIMIT_WINDOWS_MS: 60000
RATE_LIMIT_MAX: 1000
WORKSPACE: /workspace
MYSQL_CNX: '{"host":"mysql","port":3306,"user":"northwind","password":"northwind","database":"northwind","multipleStatements": true ,"waitForConnections": true }'
ports:
- '9291:9291'
expose:
- 9291
networks:
- northwind
volumes:
- ./workspace:/workspace
volumes:
mysql-data:
mysql-log:

0 comments on commit 7c52331

Please sign in to comment.