@qualithm/arrow-flight-sql-js - v0.4.3
    Preparing search index...

    Class FlightSqlClient

    Flight SQL client for executing queries and managing data with Arrow Flight SQL servers.

    const client = new FlightSqlClient({
    host: "localhost",
    port: 50051,
    tls: false,
    auth: { type: "bearer", token: "my-token" }
    })

    await client.connect()

    const result = await client.query("SELECT * FROM my_table")
    for await (const batch of result.stream()) {
    console.log(batch.numRows)
    }

    await client.close()
    Index

    Constructors

    Methods

    • Close the connection and release resources.

      Returns void

    • Establish connection to the Flight SQL server and perform authentication.

      Returns Promise<void>

      If connection cannot be established

      If authentication fails

    • Open a bidirectional data exchange with the server.

      This is the low-level API for DoExchange. For real-time subscriptions, use the higher-level subscribe() method instead.

      Parameters

      Returns ExchangeStream

      An exchange handle for sending and receiving FlightData

      const exchange = client.doExchange({
      type: DescriptorType.CMD,
      cmd: new TextEncoder().encode('SUBSCRIBE:my_topic')
      })

      // Send initial request
      await exchange.send({ appMetadata: subscribeCommand })

      // Receive responses
      for await (const data of exchange) {
      if (data.dataHeader) {
      // Process record batch
      }
      }

      // Clean up
      await exchange.end()
    • Retrieve data for a ticket as an async iterator of FlightData.

      Parameters

      • ticket: Ticket

        Ticket from FlightInfo endpoint

      Returns AsyncGenerator<
          {
              dataBody?: Uint8Array<ArrayBufferLike>;
              dataHeader?: Uint8Array<ArrayBufferLike>;
          },
          void,
          unknown,
      >

      FlightData chunks containing dataHeader and dataBody

    • Upload Arrow data to the server.

      Parameters

      • descriptor: FlightDescriptor

        Flight descriptor describing the data

      • dataStream: AsyncIterable<
            {
                appMetadata?: Uint8Array<ArrayBufferLike>;
                dataBody: Uint8Array;
                dataHeader: Uint8Array;
            },
        >

        Async iterable of FlightData messages

      Returns AsyncGenerator<{ appMetadata?: Uint8Array<ArrayBufferLike> }, void, unknown>

      Async iterator of PutResult messages

    • Execute a SQL update statement (INSERT, UPDATE, DELETE).

      Parameters

      • query: string

        SQL statement

      • Optionaloptions: ExecuteOptions

        Optional execution options

      Returns Promise<bigint>

      Number of rows affected

    • Get the list of catalogs available on the server.

      Returns Promise<CatalogInfo[]>

      Array of catalog information

      const catalogs = await client.getCatalogs()
      for (const catalog of catalogs) {
      console.log(catalog.catalogName)
      }
    • Get the foreign key relationships between two tables.

      This returns foreign keys in the foreign key table that reference the primary key of the primary key table.

      Parameters

      • options: {
            fkCatalog?: string;
            fkDbSchema?: string;
            fkTable: string;
            pkCatalog?: string;
            pkDbSchema?: string;
            pkTable: string;
        }

        Options specifying the primary key and foreign key tables

      Returns Promise<ForeignKeyInfo[]>

      Array of foreign key information

      // Find foreign keys from "orders" table that reference "users" table
      const refs = await client.getCrossReference({
      pkTable: "users",
      fkTable: "orders"
      })
    • Get the foreign keys that reference a table's primary key (exported keys).

      Parameters

      • table: string

        Table name

      • Optionalcatalog: string

        Optional catalog name

      • Optionalschema: string

        Optional schema name

      Returns Promise<ForeignKeyInfo[]>

      Array of foreign key information

      // Find all tables that reference the "users" table
      const exportedKeys = await client.getExportedKeys("users")
    • Get the foreign keys in a table (imported keys).

      Parameters

      • table: string

        Table name

      • Optionalcatalog: string

        Optional catalog name

      • Optionalschema: string

        Optional schema name

      Returns Promise<ForeignKeyInfo[]>

      Array of foreign key information

      // Find all foreign keys in the "orders" table
      const importedKeys = await client.getImportedKeys("orders")
    • Get the primary keys for a table.

      Parameters

      • table: string

        Table name

      • Optionalcatalog: string

        Optional catalog name

      • Optionalschema: string

        Optional schema name

      Returns Promise<PrimaryKeyInfo[]>

      Array of primary key information

      const primaryKeys = await client.getPrimaryKeys("users")
      for (const pk of primaryKeys) {
      console.log(`${pk.columnName} (sequence: ${pk.keySequence})`)
      }
    • Get the list of schemas available in a catalog.

      Parameters

      • Optionalcatalog: string

        Optional catalog name to filter by

      • OptionalschemaFilterPattern: string

        Optional SQL LIKE pattern to filter schema names

      Returns Promise<SchemaInfo[]>

      Array of schema information

      // Get all schemas
      const schemas = await client.getSchemas()

      // Get schemas in specific catalog
      const schemas = await client.getSchemas("my_catalog")

      // Get schemas matching pattern
      const schemas = await client.getSchemas(undefined, "public%")
    • Get SQL server information and capabilities.

      Parameters

      • OptionalinfoCodes: number[]

        Optional array of specific info codes to retrieve. If omitted, all available info is retrieved.

      Returns Promise<SqlInfo[]>

      Array of SQL info name-value pairs

      // Get all server information
      const allInfo = await client.getSqlInfo()

      // Get specific info (server name and version)
      const info = await client.getSqlInfo([0, 1])
      for (const item of info) {
      console.log(`${item.infoName}: ${item.value}`)
      }
    • Get the list of tables available.

      Parameters

      • Optionaloptions: {
            catalog?: string;
            includeSchema?: boolean;
            schemaPattern?: string;
            tablePattern?: string;
            tableTypes?: string[];
        }

        Filter options

      Returns Promise<TableInfo[]>

      Array of table information

      // Get all tables
      const tables = await client.getTables()

      // Get tables in specific catalog/schema
      const tables = await client.getTables({
      catalog: "my_catalog",
      schemaPattern: "public"
      })

      // Get only views
      const views = await client.getTables({ tableTypes: ["VIEW"] })
    • Get the list of table types supported by the server.

      Returns Promise<TableType[]>

      Array of table type names (e.g., "TABLE", "VIEW", "SYSTEM TABLE")

      const tableTypes = await client.getTableTypes()
      console.log(tableTypes) // [{ tableType: "TABLE" }, { tableType: "VIEW" }, ...]
    • Get XDBC type information supported by the server.

      Parameters

      • OptionaldataType: number

        Optional specific data type code to retrieve info for. If omitted, all types are retrieved.

      Returns Promise<XdbcTypeInfo[]>

      Array of XDBC type info objects

      // Get all supported types
      const types = await client.getXdbcTypeInfo()
      for (const t of types) {
      console.log(`${t.typeName}: SQL type ${t.dataType}`)
      }
    • Check if the client is connected.

      Returns boolean

    • Create a prepared statement for repeated execution.

      Parameters

      • query: string

        SQL query with optional parameter placeholders

      • Optionaloptions: ExecuteOptions

        Optional prepared statement options

      Returns Promise<PreparedStatement>

      PreparedStatement that can be executed multiple times

      const stmt = await client.prepare("SELECT * FROM users WHERE id = ?")
      const result = await stmt.executeQuery()
      await stmt.close()
    • Execute a SQL query and return a QueryResult for retrieving results.

      Parameters

      • query: string

        SQL query string

      • Optionaloptions: ExecuteOptions

        Optional execution options

      Returns Promise<QueryResult>

      QueryResult with stream() and collect() methods

      const result = await client.query("SELECT * FROM users")

      // Stream record batches
      for await (const batch of result.stream()) {
      console.log(batch.numRows)
      }

      // Or collect all into a table
      const table = await result.collect()
    • Subscribe to real-time data updates from a query.

      Returns a Subscription that yields RecordBatches as they arrive from the server. Automatically handles heartbeats and can reconnect on connection loss.

      Parameters

      • query: string

        SQL query to subscribe to

      • options: SubscribeOptions = {}

        Subscription options

      Returns Subscription

      Subscription handle for receiving batches and control

      const subscription = await client.subscribe(
      "SELECT * FROM events WHERE status = 'pending'",
      { mode: 'CHANGES_ONLY', heartbeatMs: 30000 }
      )

      for await (const batch of subscription) {
      console.log(`Received ${batch.numRows} rows`)
      }

      // Or with AbortController
      const controller = new AbortController()
      const subscription = await client.subscribe(query, {
      signal: controller.signal
      })

      // Later: cancel the subscription
      controller.abort()