ReadonlyfileThe file-system path that was used to open or create the database,
or null when the database was created in-memory or from a buffer.
Provides direct access to the underlying better-sqlite3
DatabaseType | Database instance.
Use this escape hatch when you need functionality that is not exposed by the GeoPackageConnection wrapper.
The raw better-sqlite3 database handle.
Executes a SQL query and returns all matching rows as an array.
The expected shape of each row object.
Defaults to Record<string, unknown>.
The SQL statement to execute (may contain ? placeholders).
Bind parameters that correspond to the placeholders in
sql.
An array of rows typed as T[]. Returns an empty array when no
rows match.
Checks whether a specific column exists in the given table.
The name of the table to inspect.
The column name to look for.
true if the column exists in the table, false otherwise.
Returns the number of rows in a table, optionally filtered by a WHERE clause.
The name of the table to count rows in.
Optionalwhere: stringAn optional SQL WHERE clause without the WHERE
keyword (e.g. "name = ?").
Bind parameters for the WHERE clause.
The row count, or 0 if the table is empty / no rows match.
Enables SQLite foreign-key constraint enforcement on this connection.
This is called automatically by all writable factory methods (open, openBuffer, create, createInMemory).
Executes one or more SQL statements that do not return data.
Unlike run, this method accepts multiple semicolon-separated statements and does not support bind parameters.
One or more SQL statements to execute.
Serialises the entire database to a Buffer.
This is especially useful for in-memory databases created with createInMemory or openBuffer when you need to persist or transmit the resulting GeoPackage.
A Buffer containing the full SQLite database image.
Executes a SQL query and returns the first matching row, or
undefined if the result set is empty.
The expected shape of the returned row object.
Defaults to Record<string, unknown>.
The SQL statement to execute (may contain ? placeholders).
Bind parameters that correspond to the placeholders in
sql.
The first row as T, or undefined when no rows match.
Executes a SQL query and returns a lazy IterableIterator over the result rows. This is more memory-efficient than all for large result sets.
The expected shape of each row object.
Defaults to Record<string, unknown>.
The SQL statement to execute (may contain ? placeholders).
Bind parameters that correspond to the placeholders in
sql.
An iterable iterator yielding rows typed as T.
Returns the maximum value of a numeric column in the given table.
The name of the table to query.
The name of the column whose maximum value is desired.
The maximum value, or null if the table is empty or all
values are NULL.
Returns the minimum value of a numeric column in the given table.
The name of the table to query.
The name of the column whose minimum value is desired.
The minimum value, or null if the table is empty or all
values are NULL.
Prepares a SQL statement for repeated execution.
The returned Statement can be executed multiple times with different parameters, which is more efficient than calling run or get in a loop.
The SQL statement to prepare (may contain ? placeholders).
A compiled better-sqlite3 Statement.
Registers a custom scalar SQL function on this database connection.
The name of the SQL function (used in queries).
The JavaScript implementation of the function. Receives SQL values as arguments and must return a SQL-compatible value.
Optionaloptions: { deterministic?: boolean; varargs?: boolean }Optional configuration for the function.
Optionaldeterministic?: booleanWhen true (the default), SQLite may
cache return values for identical inputs.
Optionalvarargs?: booleanWhen true, the function accepts a
variable number of arguments. Defaults
to false.
Executes a SQL statement that modifies data (INSERT, UPDATE, DELETE) and returns information about the changes made.
The SQL statement to execute (may contain ? placeholders).
Bind parameters that correspond to the placeholders in
sql.
A RunResult containing changes (number of rows
affected) and lastInsertRowid.
Sets the SQLite application_id pragma.
By default this writes the GeoPackage magic number (0x47504B47,
i.e. the ASCII string GPKG).
The application ID to write. Defaults to
APPLICATION_ID (0x47504B47).
Sets the SQLite user_version pragma.
By default this writes the GeoPackage specification version number
(10200, representing version 1.2.0).
The user version to write. Defaults to
USER_VERSION (10200).
Wraps the given function in a SQLite transaction.
All statements executed inside fn are committed atomically. If fn
throws, the transaction is rolled back.
The return type of the wrapped function.
A synchronous function containing the operations to run inside the transaction.
The value returned by fn.
StaticcreateCreates a new GeoPackage file at the given path.
If a file already exists at path it will be opened (and potentially
overwritten depending on subsequent operations). Foreign-key enforcement
is enabled automatically.
Absolute or relative path where the .gpkg file should
be created.
A new GeoPackageConnection instance.
StaticcreateCreates a new GeoPackage database entirely in memory.
The database can later be serialised to a Buffer with export.
Foreign-key enforcement is enabled automatically. The resulting
connection's filePath will be null.
A new in-memory GeoPackageConnection instance.
StaticopenOpens an existing GeoPackage file for reading and writing.
Foreign-key enforcement is enabled automatically.
Absolute or relative path to the .gpkg file.
A new GeoPackageConnection instance.
StaticopenOpens a GeoPackage from an in-memory Buffer.
This is useful when a GeoPackage has been fetched over the network or read from a non-file source. Foreign-key enforcement is enabled automatically.
The resulting connection's filePath will be null.
A Buffer containing the raw bytes of a GeoPackage
(SQLite) database.
A new GeoPackageConnection instance backed by the buffer.
StaticopenOpens an existing GeoPackage file in read-only mode.
Foreign-key enforcement is not enabled because the database cannot be modified.
Absolute or relative path to the .gpkg file.
A new read-only GeoPackageConnection instance.
A wrapper around a
better-sqlite3database connection tailored for working with OGC GeoPackage files.Instances are created through the static factory methods (open, openReadonly, openBuffer, create, and createInMemory) rather than by calling the constructor directly.
Example