🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@inferagraph/sql-datasource

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inferagraph/sql-datasource

SQL datasource for InferaGraph (PostgreSQL, MySQL, SQLite, MSSQL)

latest
Source
npmnpm
Version
0.1.4
Version published
Weekly downloads
14
40%
Maintainers
1
Weekly downloads
 
Created
Source

@inferagraph/sql-datasource

SQL datasource plugin for @inferagraph/core. Supports PostgreSQL, MySQL, SQLite, and MSSQL via Knex.js.

Installation

pnpm add @inferagraph/sql-datasource @inferagraph/core

You also need to install the driver for your chosen dialect:

# PostgreSQL
pnpm add pg

# MySQL
pnpm add mysql2

# SQLite
pnpm add better-sqlite3

# MSSQL
pnpm add tedious

Usage

import { SqlDatasource } from '@inferagraph/sql-datasource';

const datasource = new SqlDatasource({
  dialect: 'postgres',
  connection: {
    host: 'localhost',
    port: 5432,
    user: 'app',
    password: 'secret',
    database: 'graph_db',
  },
  autoMigrate: true, // auto-create tables on connect
});

await datasource.connect();

const view = await datasource.getInitialView();
const node = await datasource.getNode('node-1');
const neighbors = await datasource.getNeighbors('node-1', 2); // depth>1 supported
const results = await datasource.search('keyword');

await datasource.disconnect();

Multi-hop neighbors

getNeighbors(nodeId, depth) supports depth > 1. SQL has no native graph traversal, so the datasource does an application-level BFS — one 1-hop fan-out per level, deduping nodes and edges by id. Single-hop callers see no change.

Configuration

OptionTypeDescription
dialect'postgres' | 'mysql' | 'sqlite' | 'mssql'SQL dialect
connectionstring | objectKnex connection config or connection string
tables.nodesstringNode table name (default: 'nodes')
tables.edgesstringEdge table name (default: 'edges')
tables.propertiesstringEAV properties table name (default: 'node_properties')
tables.contentstringContent table name (default: 'content')
autoMigratebooleanCreate tables on connect (default: false)

SQL Schema

When autoMigrate: true, the following tables are created:

nodes

ColumnTypeDescription
idVARCHAR(255)Primary key
nameVARCHAR(500)Node display name
typeVARCHAR(100)Node type
created_atTIMESTAMPCreation timestamp
updated_atTIMESTAMPLast update timestamp

edges

ColumnTypeDescription
idVARCHAR(255)Primary key
source_idVARCHAR(255)FK to nodes.id
target_idVARCHAR(255)FK to nodes.id
typeVARCHAR(100)Relationship type
weightFLOATEdge weight (default: 1.0)
created_atTIMESTAMPCreation timestamp

node_properties (EAV)

ColumnTypeDescription
node_idVARCHAR(255)FK to nodes.id
keyVARCHAR(255)Property name
valueTEXTSerialized value
value_typeVARCHAR(50)Type hint (string, number, boolean, json)

content

ColumnTypeDescription
node_idVARCHAR(255)FK to nodes.id (PK)
contentTEXTContent body
content_typeVARCHAR(50)MIME-like type (default: 'markdown')
metadataTEXTJSON string of metadata
updated_atTIMESTAMPLast update timestamp

Dialect Support

DialectDriverStatus
PostgreSQLpgSupported
MySQLmysql2Supported
SQLitebetter-sqlite3Supported
MSSQLtediousSupported

License

MIT

FAQs

Package last updated on 06 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts