npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lambdaorm-client-node

v0.7.44

Published

Client form lambda ORM service

Downloads

680

Readme

λORM Client Node

Lambdaorm client node is an http client to consume lambdaorm service

Usage

Consume general endpoints

import { orm } from 'lambdaorm-client-node'
import { Orders } from './model'

async function execute() {
  try {
    orm.init('http://localhost:9291')
    console.log(await orm.general.ping())
    console.log(await orm.general.health())
  } catch (error: any) {
    console.error(error)
  }
}
execute()

Results:

{message: 'pong', time: '2023-11-19T04:25:36.840Z'}
{uptime: 6124.260961852, message: 'OK', time: '2023-11-19T04:25:36.846Z'}

Use lambda expression

import { orm } from 'lambdaorm-client-node'
import { Orders } from './model'

async function execute() {
  try {
    orm.init('http://localhost:9291')
    const query = (id: number) =>
      Orders.filter(p => p.id == id).include(p => [
        p.customer.map(c => c.name),
        p.details.include(d =>
          d.product.include(pr =>
            pr.category.map(cat => cat.name)
          ).map(pr => pr.name)
        ).map(d => [d.quantity, d.unitPrice]),
      ])
    const data = { id: 10248 }
    const plan = await orm.plan(query, { stage: 'default' })
    console.log(JSON.stringify(plan, null, 2))
    const result = await orm.execute(query, data, { stage: 'default' })
    console.log(JSON.stringify(result, null, 2))
  } catch (error: any) {
    console.error(error)
  }
}
execute()

Use string expression

import { orm } from 'lambdaorm-client-node'
async function execute() {
  try {
    orm.init('http://localhost:9291')
    const query = `Orders.filter(p => p.id == id)
                    .include(p => [p.customer.map(c => c.name),p.details
                      .include(d => d.product
                        .include(pr => pr.category.map(cat => cat.name))
                      .map(pr => pr.name))
                    .map(d => [d.quantity, d.unitPrice])])`
    const data = { id: 10248 }
    const plan = await orm.plan(query, { stage: 'default' })
    console.log(JSON.stringify(plan, null, 2))
    const result = await orm.execute(query, data, { stage: 'default' })
    console.log(JSON.stringify(result, null, 2))
  } catch (error: any) {
    console.error(error)
  }
}
execute()

Result of plan method:

{
  "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.CustomerID AS `__customerId`, o.OrderID AS `__id` FROM Orders o  WHERE o.OrderID = ? ",
  "children": [
    {
      "entity": "Customers",
      "dialect": "MySQL",
      "source": "default",
      "sentence": "SELECT c.CompanyName AS name, c.CustomerID AS LambdaOrmParentId FROM Customers c  WHERE  c.CustomerID IN (?) ",
      "children": []
    },
    {
      "entity": "Orders.details",
      "dialect": "MySQL",
      "source": "default",
      "sentence": "SELECT o1.Quantity AS quantity, o1.UnitPrice AS unitPrice, o1.ProductID AS `__productId`, o1.OrderID AS LambdaOrmParentId FROM `Order Details` o1  WHERE  o1.OrderID IN (?) ",
      "children": [
        {
          "entity": "Products",
          "dialect": "MySQL",
          "source": "default",
          "sentence": "SELECT p.ProductName AS name, p.CategoryID AS `__categoryId`, p.ProductID AS LambdaOrmParentId FROM Products p  WHERE  p.ProductID IN (?) ",
          "children": [
            {
              "entity": "Categories",
              "dialect": "MySQL",
              "source": "default",
              "sentence": "SELECT c1.CategoryName AS name, c1.CategoryID AS LambdaOrmParentId FROM Categories c1  WHERE  c1.CategoryID IN (?) ",
              "children": []
            }
          ]
        }
      ]
    }
  ]
}

Result of execution method:

[
  {
    "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",
    "customer": {
      "name": "Vins et alcools Chevalier"
    },
    "details": [
      {
        "quantity": 12,
        "unitPrice": 14,
        "product": {
          "name": "Queso Cabrales",
          "category": {
            "name": "Dairy Products"
          }
        }
      },
      {
        "quantity": 10,
        "unitPrice": 9.8,
        "product": {
          "name": "Singaporean Hokkien Fried Mee",
          "category": {
            "name": "Grains/Cereals"
          }
        }
      },
      {
        "quantity": 5,
        "unitPrice": 34.8,
        "product": {
          "name": "Mozzarella di Giovanni",
          "category": {
            "name": "Dairy Products"
          }
        }
      }
    ]
  }
]

Service

You can access various images at flaviorita/lambdaorm-svc

Labs

You can access various labs at github.com/lambda-orm/lambdaorm-labs

Documentation