Parses the querystrings built with @bleed-believer/kendo-grid-client fro TypeORM
npm install @bleed-believer/kendo-grid-serverSelectQueryBuilder instance based on query strings generated by @bleed-believer/kendo-grid-client. It serves as a powerful backend companion, enabling dynamic data retrieval that's perfectly aligned with frontend requests.typeorm is installed in your project:bash
npm i --save typeorm
`Then, install this library to integrate advanced query manipulation capabilities:
`bash
npm i --save @bleed-believer/kendo-grid-server
`Usage Example
$3
Define your entities as you normally would with TypeORM. Here's an example with Category and Dummy entities:
`ts
import { BaseEntity, Column, Entity, OneToMany, PrimaryGeneratedColumn, ManyToOne, Relation } from 'typeorm';@Entity({ name: 'Category' })
export class Category extends BaseEntity {
@PrimaryGeneratedColumn({ type: 'int' })
id!: number;
@Column({ type: 'varchar' })
cod!: string;
@Column({ type: 'nvarchar' })
descript!: string;
@OneToMany(() => Dummy, dummy => dummy.category)
dummies?: Relation;
}
@Entity({ name: 'Dummy' })
export class Dummy extends BaseEntity {
@PrimaryGeneratedColumn({ type: 'int' })
id!: number;
@Column({ type: 'nvarchar', length: 512 })
text!: string;
@Column({ type: 'numeric', precision: 18, scale: 2 })
value!: number;
@Column({ type: 'date' })
date!: Date;
@ManyToOne(() => Category, category => category.dummies)
category?: Relation;
}
`$3
Leverage @bleed-believer/kendo-grid-server to handle query parameters for filtering, sorting, and pagination directly in your Express route:
`ts
import { ODataQuery } from '@bleed-believer/kendo-grid-server';
import { Dummy } from '@entities/dummy.entity.js';
import express from 'express';const app = express();
app.get('/dummy', async (req, res) => {
// This is the query builder to be enhanced
const query = Dummy
.createQueryBuilder('dummy')
.innerJoinAndSelect('dummy.category', 'category');
const odata = new ODataQuery(query, req, {
date: v => v != null ? new Date(v) : v
});
const result = await odata.getRawMany();
res.contentType('json');
res.end(JSON.stringify(result));
});
app.listen(8080, () => {
console.log('Server is ready and listening on port 8080');
});
`$3
Here's an example demonstrating how to use the ODataEntity class for handling query parameters:
`ts
import { ODataEntity } from '@bleed-believer/kendo-grid-server';
import { DataSource } from 'typeorm';
import express from 'express';import { Dummy } from '@entities/dummy.entity.js';
const app = express();
const dataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'user',
password: 'password',
database: 'test',
entities: [Dummy],
synchronize: true,
});
dataSource.initialize().then(() => {
app.get('/dummy', async (req, res) => {
const odataEntity = new ODataEntity(Dummy, dataSource, req);
const result = await odataEntity.getMany({});
res.contentType('json');
res.end(JSON.stringify(result));
});
app.listen(8080, () => {
console.log('Server is ready and listening on port 8080');
});
});
``