gatelogue-types
    Preparing search index...

      gatelogue-types

      JS utility library for using Gatelogue data in JS/TS projects. It will load the database for you to access via ORM or raw SQL.

      Installation

      The data can be imported into your JavaScript/TypeScript project with classes and type definitions.

      • retrieving from npmjs.com:
        • npm: npm i gatelogue-types
        • yarn: yarn add gatelogue-types
        • pnpm: pnpm add gatelogue-types
        • denoL deno add npm:gatelogue-types
        • bun: bun add gatelogue-types
      • retrieving from jsr.io:
        • npm: npx jsr add @mrt-map/gatelogue-types
        • yarn: yarn add jsr:@mrt-map/gatelogue-types
        • pnpm: pnpm i jsr:@mrt-map/gatelogue-types
        • deno: deno add jsr:@mrt-map/gatelogue-types
        • bun: bunx jsr add @mrt-map/gatelogue-types

      To import directly from the repository:

      • npm: npm i 'https://gitpkg.vercel.app/mrt-map/gatelogue/gatelogue-types-ts?main'
      • yarn: yarn add 'https://gitpkg.vercel.app/mrt-map/gatelogue/gatelogue-types-ts?main'
      • pnpm: pnpm add mrt-map/gatelogue#path:/gatelogue-types-ts
      • bun: bun add 'git+https://gitpkg.vercel.app/mrt-map/gatelogue/gatelogue-types-ts?main'

      You will also require @sqlite.org/sqlite-wasm if on browser and better-sqlite3 if on Node.

      Usage

      To retrieve the data:

      // if on a browser:
      import { BrowserGD } from "gatelogue-types";
      import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
      const sqlite3 = await sqlite3InitModule();
      const gd = await BrowserGD.get(sqlite3); // retrieve data, no sources
      const gd = await BrowserGD.get(sqlite3, true); // retrieve data, with sources

      // if on node:
      import { NodeGD } from "gatelogue-types";
      import Database from "better-sqlite3";
      const gd = await NodeGD.get(Database); // retrieve data, no sources
      const gd = await NodeGD.get(Database, true); // retrieve data, with sources

      Using the ORM does not require SQL and makes for generally clean code. However, doing this is very inefficient as each attribute access is one SQL query.

      for (const airport of gd.airAirports) {
      for (const gate of airport.gates) {
      console.log(`Airport ${airport.code} has gate ${gate.code}`);
      }
      }

      Querying the underlying SQLite database directly with sql.js is generally more efficient and faster. It is also the only way to access the *Source tables, if you retrieved the database with those.

      for (const [airportCode, gateCode] of gd.execGetMany<[string, string]>(
      "SELECT A.code, G.code FROM AirGate G INNER JOIN AirAirport A ON G.airport = A.i")
      ) {
      console.log(`Airport ${airportCode} has gate ${gateCode}`);
      }
      AirAirline
      AirAirport
      Aircraft
      AirFlight
      AirGate
      BrowserGD
      BusBerth
      BusCompany
      BusConnection
      BusLine
      BusStop
      GD
      LocatedNode
      Node
      NodeGD
      Proximity
      RailCompany
      RailConnection
      RailLine
      RailPlatform
      RailStation
      SeaCompany
      SeaConnection
      SeaDock
      SeaLine
      SeaStop
      SpawnWarp
      Town
      AirMode
      BusMode
      ID
      RailMode
      Rank
      SeaMode
      WarpType
      World