Skip to content

Commit

Permalink
implement jsonObject dialect (#101)
Browse files Browse the repository at this point in the history
* implement jsonObject dialect

* fix lint errors

* validate json objects

* add before and after execute events

* update readme

* 2.9.0
  • Loading branch information
kbarbounakis authored Feb 1, 2025
1 parent fa98f7f commit 5d2f4b4
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jsconfig.json
.gitpod.yml
.gitpod.dockerfile

# docs
docs

#github
.github

Expand Down
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
![GitHub last commit](https://img.shields.io/github/last-commit/themost-framework/sqlite)
![GitHub Release Date](https://img.shields.io/github/release-date/themost-framework/sqlite)
[![npm](https://img.shields.io/npm/dw/@themost/sqlite)](https://www.npmjs.com/package/@themost%2Fsqlite)
![Snyk Vulnerabilities for npm package](https://img.shields.io/snyk/vulnerabilities/npm/@themost/sqlite)

![MOST Web Framework Logo](https://github.com/themost-framework/common/raw/master/docs/img/themost_framework_v3_128.png)

Expand Down Expand Up @@ -40,16 +39,32 @@ Register SQLite adapter on app.json as follows:
]
}

or create a new instance of `SqliteAdapter` class for connecting to SQLite database.

#### Post Installation Note:
SQLite Data Adapter comes with a regular expression extension for SQLite (regexp.c). You have to compile this extension as follows:
```javascript
const { SqliteAdapter } = require('@themost/sqlite');
const { QueryExpression } = require('@themost/query');
const db = new SqliteAdapter({
database: 'db/local.db'
});
const query = new QueryExpression()
.select(({ id, name, category, model, price }) => ({
id,
name,
category,
model,
price,
})).from('ProductData')
.where((x) => {
return x.price > 500 && x.category === "Laptops";
})
.orderByDescending((x) => x.price)
.take(10);
```

##### Using GCC/MinGW on Windows and Linux
gcc -shared -fPIC -Isqlite3 -o regexp.0.dylib regexp.c
Read more about [MOST Web Framework query language provided by @themost/query](https://github.com/themost-framework/query?#themostquery)

##### Using GCC on Mac OSX
gcc -dynamiclib -fPIC -Isqlite3 -o regexp.0.dylib regexp.c
Use [query playground project at codesanbox.io](https://codesandbox.io/p/devbox/query-playground-zc8fg9) to learn more about the query language specification of [@themost-framework](https://github.com/themost-framework)

##### Microsoft Tools on Windows
cl /Gd regexp.c /I sqlite3 /DDLL /LD /link /export:sqlite3_extension_init /out:regexp.0.dylib
![codesandbox.io_query-playground-1.png](docs/img/codesandbox.io_query-playground-1.png)

8 changes: 8 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ module.exports = {
}
]
],
plugins: [
[
'@babel/plugin-proposal-decorators',
{
'legacy': true
}
]
]
};
Binary file added docs/img/codesandbox.io_query-playground-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/codesandbox.io_query-playground-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const config = {
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,
collectCoverage: true,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
Expand Down
6 changes: 5 additions & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
process.env.NODE_ENV='development';
require('dotenv').config();
const { JsonLogger } = require('@themost/json-logger');
const { TraceUtils } = require('@themost/common');
process.env.NODE_ENV = 'development';
TraceUtils.useLogger(new JsonLogger());
/* global jest */
jest.setTimeout(30000);
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"experimentalDecorators": true,
"paths": {
"@themost/sqlite": [
"src/index"
Expand Down
102 changes: 86 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@themost/sqlite",
"version": "2.8.4",
"version": "2.9.0",
"description": "MOST Web Framework SQLite Adapter",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -28,6 +28,7 @@
"sqleanVersion": "0.27.1"
},
"dependencies": {
"@themost/events": "^1.5.0",
"async": "^2.6.4",
"sprintf-js": "^1.1.2",
"sqlite3": "^5.1.7",
Expand All @@ -41,15 +42,16 @@
"@babel/core": "^7.26.0",
"@babel/eslint-parser": "^7.25.9",
"@babel/eslint-plugin": "^7.25.1",
"@babel/plugin-proposal-decorators": "^7.25.9",
"@babel/preset-env": "^7.26.0",
"@babel/register": "^7.25.9",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^22.0.0",
"@themost/common": "^2.11.0",
"@themost/data": "^2.14.2",
"@themost/events": "^1.3.0",
"@themost/data": "^2.18.1",
"@themost/json-logger": "^1.1.0",
"@themost/peers": "^1.0.2",
"@themost/query": "^2.14.5",
"@themost/query": "^2.14.7",
"@themost/xml": "^2.5.2",
"@types/jasmine": "^5.1.4",
"dotenv": "^16.0.0",
Expand Down
2 changes: 0 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { babel } from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import * as pkg from './package.json';
import dts from 'rollup-plugin-dts';

Expand All @@ -13,7 +12,6 @@ export default [
},
external: Object.keys(pkg.dependencies).concat(Object.keys(pkg.peerDependencies)),
plugins: [
commonjs(),
babel({ babelHelpers: 'bundled' })
]
},
Expand Down
13 changes: 9 additions & 4 deletions spec/DateFunctions.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TestApplication } from './TestApplication';
import moment from 'moment';

describe('DateFunctions', () => {
/**
Expand Down Expand Up @@ -36,11 +37,13 @@ describe('DateFunctions', () => {
it('should use getDay()', async () => {
await app.executeInTestTranscaction(async (context) => {
let items = await context.model('Order')
.asQueryable().where('orderDate').getDay().equal(15).silent().getItems();
.asQueryable().where('orderDate').getDate().getDay().equal(15).silent().take(10).getItems();
expect(Array.isArray(items)).toBeTruthy();
expect(items.length).toBeGreaterThan(0);
for (const item of items) {
expect(item.orderDate.getDate()).toEqual(15);
const orderDate = item.orderDate;
const dayOfMonth = parseInt(moment.utc(orderDate).format('D'), 10);
expect(dayOfMonth).toEqual(15);
}
});
});
Expand All @@ -52,7 +55,8 @@ describe('DateFunctions', () => {
expect(Array.isArray(items)).toBeTruthy();
expect(items.length).toBeGreaterThan(0);
for (const item of items) {
expect(item.orderDate.getMonth()).toEqual(3);
const orderMonth = parseInt(moment.utc(item.orderDate).format('M'), 10);
expect(orderMonth).toEqual(4);
}
});
});
Expand All @@ -77,7 +81,8 @@ describe('DateFunctions', () => {
expect(Array.isArray(items)).toBeTruthy();
expect(items.length).toBeGreaterThan(0);
for (const item of items) {
expect(item.orderDate.getHours()).toEqual(14);
const hour = parseInt(moment.utc(item.orderDate).format('H'), 10);
expect(hour).toEqual(14);
}
});
});
Expand Down
Loading

0 comments on commit 5d2f4b4

Please sign in to comment.