lumnik. / scenarios All scenarios · Français

Sequelize: the service announces 260 orders for 130

Goal Read every order of a Node service through its API without believing a wrong total.

An Express and Sequelize service, 130 orders and their lines, read by offset and limit.

manifests/lab-docker-compose.yml
name: lumnik-scenario-sequelizeservices:  orders:    build: ../lab    ports: ["127.0.0.1:${SEQUELIZE_PORT:-9360}:3000"]
manifests/10-orders.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-sequelize-a  connector_type: rest-generic  scopes: [ventes]spec:  base_url: http://host.docker.internal:9360  endpoints:    - id: orders      path: /orders      method: GET      pagination: { kind: sequelize, limit: 50 }            # ?offset=0&limit=50, reads $.rows, checks $.count      target:        kind: hybrid        table: ext.scenario_sequelize_a        unique_key: $.id        promote:          - { name: reference, path: $.reference, type: text }          - { name: customer, path: $.customer, type: text }
manifests/20-orders-with-lines.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-sequelize-lines-a  connector_type: rest-generic  scopes: [ventes]spec:  base_url: http://host.docker.internal:9360  endpoints:    - id: orders      path: /orders-with-lines      method: GET      pagination: { kind: sequelize, limit: 50 }            # findAndCountAll with include: $.count counts the lines      target:        kind: hybrid        table: ext.scenario_sequelize_lines_a        unique_key: $.id        promote:          - { name: reference, path: $.reference, type: text }          - { name: customer, path: $.customer, type: text }
manifests/30-orders-with-lines-distinct.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-sequelize-distinct-a  connector_type: rest-generic  scopes: [ventes]spec:  base_url: http://host.docker.internal:9360  endpoints:    - id: orders      path: /orders-with-lines-distinct      method: GET      pagination: { kind: sequelize, limit: 50 }            # the same with distinct: true      target:        kind: hybrid        table: ext.scenario_sequelize_distinct_a        unique_key: $.id        promote:          - { name: reference, path: $.reference, type: text }          - { name: customer, path: $.customer, type: text }
manifests/40-orders-watched.yaml
apiVersion: connectors.lumnik.io/v1kind: Connectormetadata:  name: scenario-sequelize-watched-a  connector_type: rest-generic  scopes: [ventes]spec:  base_url: http://host.docker.internal:9360  default_rate_limit: 1/s                              # a gentle reader: fourteen pages take fourteen seconds  endpoints:    - id: orders      path: /orders      method: GET      pagination: { kind: sequelize, limit: 10 }      target:        kind: hybrid        table: ext.scenario_sequelize_watched_a        unique_key: $.id        promote:          - { name: reference, path: $.reference, type: text }          - { name: customer, path: $.customer, type: text }

Limits

  • lumnik cannot tell a wrong total from missing rows: it refuses both. The fix lives in the service.
  • A deleted order stays in the hub's table: a full read adds and updates, it does not erase.
  • 130 fictional orders, created when the service starts.

Sales · orders

The orders live in a Node service.

Every one must be read, with its lines.

Express, Sequelize 6.37, 130 orders

The problem

The API returns the list in pages.

  • offset and limit, 50 per page.
  • Every page gives a count.

What is not changed

The service stays as it is.

  • Its API, read only.
  • No module, no setting.

The trap

The count counts the joined lines.

  • include without distinct: true.
  • 260 announced for 130 orders.

What had to be written

pagination: { kind: sequelize }

One line.

  • Each page's count is checked.
  • A 21-line connector.

When the total is wrong

The run fails, it does not lie.

  • 260 announced, 130 read.
  • The message gives both numbers.

The fix

It lives in the service.

  • distinct: true in findAndCountAll.
  • 130 of 130, read again if the list moves.

Try it

The scenario replays locally.

Every step is published with its output.

This scenario runs on lumnik Open, free and open source.

Try lumnik Open →