geopackage-ts
    Preparing search index...

    Class AttributeDao

    Data Access Object for querying and manipulating rows in a GeoPackage attribute (non-spatial) table.

    Inherits all generic CRUD methods from UserDao, including queryForAll, queryWhere, queryById, insert, update, deleteWhere, deleteById, and count.

    const dao = new AttributeDao(conn, attributeTable);

    // Iterate over all rows
    for (const row of dao.queryForAll()) {
    console.log(row);
    }

    // Count rows
    console.log(`Total rows: ${dao.count()}`);

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    The underlying database connection.

    table: UserTable

    The user table schema that this DAO operates on.

    Accessors

    • get tableName(): string

      Gets the name of the table managed by this DAO.

      Returns string

      The table name string.

    Methods

    • Counts rows in the table, optionally filtered by a WHERE clause.

      Parameters

      • Optionalwhere: string

        An optional SQL WHERE clause (without the WHERE keyword).

      • ...params: unknown[]

        Bind parameters for placeholders in the WHERE clause.

      Returns number

      The count of matching rows.

      const total = dao.count();
      const active = dao.count('"status" = ?', 1);
    • Deletes a single row by its primary key value.

      Parameters

      • id: number

        The primary key value of the row to delete.

      Returns number

      The number of rows deleted (0 or 1).

      const deleted = dao.deleteById(42);
      console.log(deleted ? 'Row deleted' : 'Row not found');
    • Deletes rows matching a SQL WHERE clause.

      Parameters

      • where: string

        A SQL WHERE clause (without the WHERE keyword).

      • ...params: unknown[]

        Bind parameters for placeholders in the WHERE clause.

      Returns number

      The number of rows deleted.

      const deleted = dao.deleteWhere('"status" = ?', 0);
      console.log(`Deleted ${deleted} row(s)`);
    • Inserts a new row into the table.

      The row's values are inserted into the corresponding columns. The primary key value from the row is typically omitted to allow AUTOINCREMENT to assign an ID automatically.

      Parameters

      • row: UserRow

        The UserRow to insert. The values record determines which columns are set.

      Returns number

      The last inserted row ID (the auto-generated primary key).

      const row = createUserRow(table, { name: 'New Feature' });
      const newId = dao.insert(row);
      console.log(`Inserted row with ID: ${newId}`);
    • Queries a single row by its primary key value.

      Type Parameters

      • T = Record<string, unknown>

        The expected row type. Defaults to Record<string, unknown>.

      Parameters

      • id: number

        The primary key value to look up.

      Returns T | undefined

      The matching row, or undefined if no row with the given ID exists.

      const row = dao.queryById(42);
      if (row) {
      console.log('Found:', row);
      }
    • Queries all rows from the table.

      Returns a lazy iterable iterator that yields rows one at a time, which is memory-efficient for large tables.

      Type Parameters

      • T = Record<string, unknown>

        The expected row type. Defaults to Record<string, unknown>.

      Returns IterableIterator<T>

      An iterable iterator over all rows in the table.

      for (const row of dao.queryForAll()) {
      console.log(row);
      }
    • Queries rows matching a SQL WHERE clause.

      Returns a lazy iterable iterator that yields matching rows one at a time.

      Type Parameters

      • T = Record<string, unknown>

        The expected row type. Defaults to Record<string, unknown>.

      Parameters

      • where: string

        A SQL WHERE clause (without the WHERE keyword).

      • ...params: unknown[]

        Bind parameters for placeholders in the WHERE clause.

      Returns IterableIterator<T>

      An iterable iterator over the matching rows.

      for (const row of dao.queryWhere('"status" = ?', 1)) {
      console.log(row);
      }
    • Updates an existing row in the table, identified by its primary key.

      All columns present in row.values (except the primary key column itself) are updated. The primary key column value is used in the WHERE clause to identify the target row.

      Parameters

      • row: UserRow

        The UserRow containing updated values. Must include the primary key value.

      Returns number

      The number of rows affected by the update (typically 0 or 1).

      const row = createUserRow(table, { id: 42, name: 'Updated Name' });
      const affected = dao.update(row);
      console.log(`Updated ${affected} row(s)`);