From 77524f607c3308388c0d2a8c259c5e4b4634f489 Mon Sep 17 00:00:00 2001 From: j3lte Date: Thu, 7 Dec 2023 00:32:33 +0100 Subject: [PATCH] README --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ deno.lock | 12 ++++++++++ 2 files changed, 80 insertions(+) diff --git a/README.md b/README.md index 6e4b61d..4fcb89b 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,74 @@ Node: > npm install rdw-data -s ``` +## Usage + +```typescript + +import { + KentekenVoertuigen, + KentekenVoertuigenAssen, + KentekenVoertuigenBrandstof, + KentekenVoertuigenCarrosserie, + KentekenVoertuigenCarrosserieSpecificatie, + KentekenVoertuigenVoertuigklasse, + Select, + Where, +} from "https://deno.land/x/rdw_data/mod.ts"; + +/* + * Example: search for a license plate and combine the results + */ +const search = ( + kenteken: string, +): Promise< + & KentekenVoertuigen.ResponseData + & KentekenVoertuigenAssen.ResponseData + & KentekenVoertuigenBrandstof.ResponseData + & KentekenVoertuigenCarrosserie.ResponseData + & KentekenVoertuigenCarrosserieSpecificatie.ResponseData + & KentekenVoertuigenVoertuigklasse.ResponseData +> => + Promise.all([ + KentekenVoertuigen.RDWQuery().where( + Where.like(KentekenVoertuigen.Fields.Kenteken, kenteken), + ).single(), + KentekenVoertuigenAssen.RDWQuery().where( + Where.like(KentekenVoertuigenAssen.Fields.Kenteken, kenteken), + ).single(), + KentekenVoertuigenBrandstof.RDWQuery().where( + Where.like(KentekenVoertuigenBrandstof.Fields.Kenteken, kenteken), + ).single(), + KentekenVoertuigenCarrosserie.RDWQuery().where( + Where.like(KentekenVoertuigenCarrosserie.Fields.Kenteken, kenteken), + ).single(), + KentekenVoertuigenCarrosserieSpecificatie.RDWQuery().where( + Where.like(KentekenVoertuigenCarrosserieSpecificatie.Fields.Kenteken, kenteken), + ).single(), + KentekenVoertuigenVoertuigklasse.RDWQuery().where( + Where.like(KentekenVoertuigenVoertuigklasse.Fields.Kenteken, kenteken), + ).single(), + ]).then((results) => { + return results.reduce((acc, result) => { + return { + ...acc, + ...(result.data || {}), + }; + }, {}); + }); + +// We can also count the number of result in a database +const { data } = await KentekenVoertuigen.RDWQuery().select( + Select().count(), +).single(); + +// Let's search. Kenteken (License plate) should only have letters and numbers, no dashes ('-') +const combined = await search("XXXXX"); + +console.log(data.count); +console.log(combined); + +``` ## API diff --git a/deno.lock b/deno.lock index f538a16..e32ed69 100644 --- a/deno.lock +++ b/deno.lock @@ -136,6 +136,18 @@ "https://deno.land/x/eta@v1.14.2/render.ts": "c6bdc538cb9c2ffc1593ac7ce0fd55c711a65cd6a909b097c913ea47056badb4", "https://deno.land/x/eta@v1.14.2/storage.ts": "46f762d1c04d9095ed6fb694c0d993e9ae507a69bab469a5a3bd23a5a9a79983", "https://deno.land/x/eta@v1.14.2/utils.ts": "e30a240bded14fde639287c8fb1f826c86c22c50264f4c69a266100307c381a9", + "https://deno.land/x/soda@0.4.5/mod.ts": "9473507398048cb24dbb37b3a220777106c69c28d573898648deb2bb84a7e131", + "https://deno.land/x/soda@0.4.5/src/Field.ts": "9fc581658df580392c861f6a152e2d6a2b8ebae5e013234697ff6974063dcfe8", + "https://deno.land/x/soda@0.4.5/src/Order.ts": "5270062ee65c62aa4045eb1ad7faf9916c2cbbca444dbe2b0c4d52113f45e3b1", + "https://deno.land/x/soda@0.4.5/src/Query.ts": "4809d0c9af5bf9174cf30826b6d2a0aeebbc6b1d480349af0426892e3bc18e7a", + "https://deno.land/x/soda@0.4.5/src/Select.ts": "88adb228699cba90c74881c4a03ce7fdc18cecbab5c31d83072b99ad0227d70b", + "https://deno.land/x/soda@0.4.5/src/SelectImpl.ts": "e679b5742ae19b0a3d899c9aea8ccbffbb16c061bc71431a3075e85a9ba1c068", + "https://deno.land/x/soda@0.4.5/src/Where.ts": "204a318a111011a1f27f93491cbdf4ceac6bef84a10d66f72eeabf167342036e", + "https://deno.land/x/soda@0.4.5/src/mod.ts": "932d444c0099a68b08b298c99473b4bbdf7370e5547321091ae2aacab13e97c8", + "https://deno.land/x/soda@0.4.5/src/types.ts": "371dc0972a2ead5c32d63fbb0cbc314adff0b79ce8f40b4d0aabb42b015185fa", + "https://deno.land/x/soda@0.4.5/src/utils/expr.ts": "114e23f4e8b0cb0d5723ff576b4652dc35f597327a0e8438f67643da8e0a32d5", + "https://deno.land/x/soda@0.4.5/src/utils/param.ts": "cd0663ad2836aba71c18b6d82637ccdaac51e057c2db0eaa59367b7d158ed8c7", + "https://deno.land/x/soda@0.4.5/src/utils/qs.ts": "433093d956607a60e6bdb20fb9fa25c26ef1c12b52b74e69dab86392ae05d0ae", "https://deno.land/x/ts_morph@18.0.0/bootstrap/mod.ts": "b53aad517f106c4079971fcd4a81ab79fadc40b50061a3ab2b741a09119d51e9", "https://deno.land/x/ts_morph@18.0.0/bootstrap/ts_morph_bootstrap.js": "6645ac03c5e6687dfa8c78109dc5df0250b811ecb3aea2d97c504c35e8401c06", "https://deno.land/x/ts_morph@18.0.0/common/DenoRuntime.ts": "6a7180f0c6e90dcf23ccffc86aa8271c20b1c4f34c570588d08a45880b7e172d",