Version: 1.0
NQL translates to multiple backend types:
NQL → PostgreSQL
→ MySQL
→ MongoDB
→ GraphQL
→ REST APIs
function translateToPostgreSQL(nqlQuery) {
const { operation, resource, params } = nqlQuery;
if (operation === 'read') {
return {
sql: `
SELECT ${params.fields?.join(', ') || '*'}
FROM ${resource}
WHERE ${buildWhere(params.filter)}
ORDER BY ${buildOrderBy(params.sort)}
LIMIT ${params.limit || 'ALL'}
OFFSET ${params.offset || 0}
`,
params: extractParams(params.filter)
};
}
if (operation === 'create') {
const fields = Object.keys(params.data);
return {
sql: `
INSERT INTO ${resource} (${fields.join(', ')})
VALUES (${fields.map((_, i) => `$${i + 1}`).join(', ')})
RETURNING *
`,
params: Object.values(params.data)
};
}
// ... other operations
}function translateToMongoDB(nqlQuery) {
const { operation, resource, params } = nqlQuery;
if (operation === 'read') {
return {
collection: resource,
operation: 'find',
query: buildMongoFilter(params.filter),
options: {
projection: buildProjection(params.fields),
sort: buildMongoSort(params.sort),
limit: params.limit,
skip: params.offset
}
};
}
// ... other operations
}function translateToGraphQL(nqlQuery) {
const { operation, resource, params } = nqlQuery;
if (operation === 'read') {
return {
query: `
query {
${resource}(
where: ${buildGraphQLWhere(params.filter)}
orderBy: ${buildGraphQLOrder(params.sort)}
limit: ${params.limit}
offset: ${params.offset}
) {
${params.fields.join('\n')}
}
}
`
};
}
// ... other operations
}Version: 1.0
License: MIT
Author: nagibaba