Registry / database / azure-odata-sql

azure-odata-sql

JSON →
library0.2.0jsnpmunverified

Converts OData query objects (as produced by azure-query-js) into parameterized SQL statements for mssql and sqlite. Version 0.2.0 is the latest stable release; the library is lightweight with a single `format` function and uses mssql types for parameter definitions. It supports skip, take, filters, ordering, inline count, and soft delete, making it a focused bridge between OData and SQL without a full ORM.

npm install azure-odata-sql
INSTALL
IMPORT
SIG · AZURE-ODATA-SQL
A
azure-odata-sql
databasejavascriptv0.2.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.

format
import { format } from 'azure-odata-sql';
const format = require('azure-odata-sql');
ESM and CommonJS both supported; named export only.
format
const { format } = require('azure-odata-sql');
const azureOdataSql = require('azure-odata-sql');
CommonJS users must destructure the named export.
format
import { format } from 'azure-odata-sql';
import format from 'azure-odata-sql';
There is no default export; must use named import.

Demonstrates converting a basic OData query with selections, filters, and pagination to a parameterized SQL statement.

import { format } from 'azure-odata-sql'; const query = { selections: ['id', 'name', 'email'], filters: [{ field: 'status', operator: 'eq', value: 'active' }], take: 10, skip: 0 }; const tableConfig = { name: 'users', schema: 'dbo', flavor: 'mssql', softDelete: false }; const result = format(query, tableConfig); console.log('SQL:', result.query[0]); console.log('Parameters:', result.query[1]);
Debug
Known issues
gotchaThe `flavor` field in tableConfig must be either 'mssql' or 'sqlite'; other values cause errors.
fix
Always set tableConfig.flavor to 'mssql' or 'sqlite'.
affects: >=0.0.0
gotchaParameter types are based on mssql; ensure the `mssql` package is installed even if using sqlite flavor.
fix
Install mssql: npm install mssql
affects: >=0.0.0
gotchaThe `resultLimit` property in query object does not correspond to SQL LIMIT; it triggers a different SQL clause depending on flavor.
fix
Use `take` for LIMIT/Top and `skip` for OFFSET instead of `resultLimit`.
affects: >=0.0.0
gotchaInlineCount is only supported when `inlineCount` is set to the string 'allpages'; other values (including true) will not produce a count query.
fix
Set inlineCount: 'allpages' explicitly.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'query')
Calling format() with undefined or missing query object.
fix
Ensure query is an object with at least one property (e.g., { take: 10 }).
Error: Unsupported flavor. Supported flavors: mssql, sqlite
tableConfig.flavor is set to an unsupported value (e.g., 'mysql').
fix
Use 'mssql' or 'sqlite'.
Error: Parameters must be an object.
Passing a non-object as the second argument (tableConfig).
fix
Provide an object with at least a `name` property.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
mssqlrequiredTypes for parameter representation (e.g., TYPES.NVarChar)
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
azure-odata-sql — npm install azure-odata-sql · libregistry