Registry / database / sqlite-tg

sqlite-tg

JSON →
library0.0.1-alpha.19jsnpmunverified

sqlite-tg is an experimental SQLite extension for limited geospatial operations, currently at version 0.0.1-alpha.19. Released as alpha with no fixed cadence, it provides basic geospatial functions (e.g., point-in-polygon, distance) via a loadable extension. Ship TypeScript types. Differentiators: lightweight, no external dependencies, integrates directly with SQLite. Not suitable for production or complex spatial analysis.

npm install sqlite-tg
INSTALL
IMPORT
SIG · SQLITE-TG
S
sqlite-tg
databasejavascriptv0.0.1-alpha.19
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sqlite-tg
import Database from 'better-sqlite3'; import 'sqlite-tg'; const db = new Database(':memory:'); db.loadExtension('tg');
import tg from 'sqlite-tg';
sqlite-tg is a SQLite extension, not a JS module. You need to load it via db.loadExtension() after opening a database.
tgConfig
import { tgConfig } from 'sqlite-tg';
Exported as named ESM symbol, but package has no default export.
tgVersion
import { tgVersion } from 'sqlite-tg';
const tgVersion = require('sqlite-tg').tgVersion;
Package is ESM-only (since alpha). Require will fail.

Shows how to load the sqlite-tg extension, use tg_version() and a geospatial function (point_in_polygon) with better-sqlite3.

import Database from 'better-sqlite3'; import { tgVersion } from 'sqlite-tg'; const db = new Database(':memory:'); db.loadExtension('tg'); const result = db.prepare("SELECT tg_version() AS ver").get(); console.log(result); // Use geospatial functions db.exec(`CREATE TABLE points (id INTEGER PRIMARY KEY, lat REAL, lon REAL)`); db.prepare(`INSERT INTO points (lat, lon) VALUES (?, ?)`).run(40.7128, -74.0060); const row = db.prepare(`SELECT tg_point_in_polygon(lat, lon, 'POLYGON((-74.1 40.7, -73.9 40.7, -73.9 40.8, -74.1 40.8, -74.1 40.7))') AS in_nyc FROM points LIMIT 1`).get(); console.log(in_nyc); // Expected output: { in_nyc: 1 }
Debug
Known issues
gotchasqlite-tg is alpha software (v0.0.1-alpha.19). API may break without notice. Not for production.
fix
Pin exact version and test thoroughly before upgrading.
affects: <1.0.0
breakingPackage is ESM-only. Using require() results in error 'ERR_REQUIRE_ESM'.
fix
Use import syntax or dynamic import().
affects: >=0.0.1-alpha.0
gotchasqlite-tg is a native extension; requires compilation for target platform. Prebuilt binaries may be limited.
fix
Ensure your platform has a prebuilt binary or install build tools (node-gyp, cmake).
affects: *
gotchaLimited geospatial support: only basic functions. Not a replacement for SpatiaLite or PostGIS.
fix
Check documentation for supported functions before adopting.
affects: *
gotchaThe extension must be loaded via db.loadExtension('tg') before usage. Failure to do so yields 'no such module: tg'.
fix
Call db.loadExtension('tg') after opening the database.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'sqlite-tg'
Package not installed or ESM-only import used in CommonJS context.
fix
npm install sqlite-tg and ensure your project uses ESM (type: module in package.json or .mjs extension).
TypeError: db.loadExtension is not a function
Using a database driver that doesn't support loadExtension (e.g., sql.js).
fix
Use better-sqlite3 or node-sqlite3 which support loadExtension.
Error: no such module: tg
Extension not loaded or path to extension binary is wrong.
fix
Call db.loadExtension('tg') after database connection and ensure the extension binary is installed.
Error: ERR_REQUIRE_ESM
Using require() to import ESM-only package.
fix
Replace require with import or use dynamic import().
Upgrade
Version history
0.0.1-alpha.19latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources
sqlite-tg — npm install sqlite-tg · libregistry