@cap.core/ql
v1.2.6
Published
Minimalistic implementation of cds.ql, carved out from CAP.
Downloads
501
Readme
Minimalistic cds.ql
This is a minimalistic implementation of cds.ql that supports parsing and constructing SQL and CQL queries into CQN objects. It provides a fluent API for constructing queries as well as a parser for CQL strings, including tagged template literals.
Setup
npm add cap-js/qlUsage
Import from ESM modules, or from CommonJS modules:
import { cql } from '@cap.core/ql'const { cql } = require ('@cap.core/ql')Then construct queries like so:
cql`SELECT ID, title from Books`cql`SELECT from Authors {
ID, name, books {
ID, title, genre.name as genre
}
}`Try it in Node REPL
Start Node's REPL from your command line:
nodeWithin there import the cql function:
const { cql } = await import ('@cap.core/ql')Then copy and paste this:
let ID = 201
cql`INSERT into Books ${{ ID, title:'Wuthering Heights' }}`
cql`UPSERT into Books ${{ ID, title:'Wuthering Heights' }}`
cql`UPDATE Books with ${{ stock:111 }} where ID=${ID}`
cql`SELECT ID, title, stock from Books where ID=${ID}`
cql`DELETE from Books where ${[ID]}`
cql`DELETE Books[${ID}]` // → same as above⇒ the constructed CQN query objects are printed as output.
Contribute
Feel invited to contribute.
git clone https://github.com/cap-js/ql cap/core/ql
cd cap/core/ql
npm iTry it in REPL or Browser
Launch Node's REPL, with cqn and all other API entry points preloaded into global constants:
npm run in:replAlternatively, launch a server and open http://localhost:4004 in your browser:
npm run in:browserThen try out the API in your browser's Developer Tools console – for example, copy and paste the sample lines above to start with.
Running Tests
npx vitestcds testchestThe latter ones are for users of CAP in general, or @cap.core/cds-test in particular.
