Registry / database / gatsby-source-sqlite

gatsby-source-sqlite

JSON →
library1.0.0jsnpmunverified

A Gatsby source plugin that pulls data from a SQLite database file into Gatsby's GraphQL layer. Version 1.0.0 stable. It supports multiple queries, joins (one-to-one, one-to-many), and remote image downloading for processing with gatsby-plugin-sharp. The plugin requires gatsby >2.0.0 and gatsby-source-filesystem >2.0.0 as peer dependencies. It is a fork of gatsby-source-mysql, modified to use SQLite. Key differentiators: simple configuration, direct SQL queries, and built-in relationship mapping.

npm install gatsby-source-sqlite
INSTALL
IMPORT
SIG · GATSBY-SOURCE-SQLI
G
gatsby-source-sqlite
databasejavascriptv1.0.0
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.

plugin
module.exports = { plugins: [{ resolve: 'gatsby-source-sqlite', options: { ... } }] }
module.exports = { plugins: ['gatsby-source-sqlite'] }
Must provide options object with fileName and queries.

Sets up gatsby-source-sqlite in Gatsby config to query a SQLite database file and make data available via GraphQL.

// gatsby-config.js module.exports = { plugins: [ { resolve: `gatsby-source-sqlite`, options: { fileName: './data/mydb.sqlite', queries: [ { statement: 'SELECT * FROM country', idFieldName: 'Code', name: 'country' } ] } } ] };
Debug
Known issues
gotchaThe plugin requires both 'gatsby' and 'gatsby-source-filesystem' as peer dependencies. Missing them will cause crashes at build time.
fix
Install both: npm install gatsby gatsby-source-filesystem
affects: >=1.0.0
gotchaThe 'idFieldName' must be a column that is unique; using a non-unique field may lead to node ID collisions and overwritten data.
fix
Ensure the specified column has unique values (e.g., primary key).
affects: >=1.0.0
gotchaJoins (parentName, foreignKey) currently only support one-to-one and one-to-many cardinalities. Many-to-many is not supported.
fix
Restructure your queries to avoid many-to-many, or raise an issue on GitHub.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'createNode' of (intermediate value) as it is undefined.
Missing 'gatsby-source-filesystem' peer dependency or misconfigured gatsby-config.
fix
Install gatsby-source-filesystem and add it to plugins array in gatsby-config.js.
Error: Cannot find module 'sql.js'.
The underlying sql.js package (transitive dependency) is not automatically installed.
fix
Run: npm install sql.js
Error: The 'statement' option is required for each query.
A query object is missing the 'statement' field.
fix
Add a valid SQL SELECT statement to each query object.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
gatsbyrequiredpeer dependency - plugin runs only within Gatsby ecosystem
gatsby-source-filesystemrequiredpeer dependency - required for file handling
Agent activity
8 hits · last 30 days
node
8
Resources
gatsby-source-sqlite — npm install gatsby-source-sqlite · libregistry