1.0.13 • Published 5 months ago

hquery-store v1.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

Hquery-store

Hquery Store is a utility module designed to assist in validating and optimizing queries for a given schema. This module is particularly useful when working with database queries, ensuring that the requested fields are valid and optimizing the query by sorting columns based on the specified schema order.

Author

  • Himanshu Chauhan

Function

ValidateFields(request, TableName, excludeKeys = [])

This function validates the fields in the request against the provided schema (TableName). It returns an object containing the status and columns if successful, or an error object if validation fails.

request: The request object containing the fields to be validated. TableName: The schema object representing the table structure. excludeKeys: An optional array of keys to exclude from validation.

Usage

1. **Installation:**

   Install Hquery-store using npm:

   ``` npm install hquery-store --save```

### AdonisTs Integration

import {ValidateFields} from 'hquery-store/Hquery'

// Define your schema, e.g., EmployeeMaster
const EmployeeMaster = {
  tableName: 'EmployeeMaster', // required field
  id: 'Id',
  fname: 'FirstName',
  lname: 'LastName',
  email: 'CompanyEmail',
  activeSts: 'Is_Delete',
  password: 'Password',
  orgid: 'OrganizationId',
  desc: 'Description'
};

// Example route using Hquery Store
Route.post('/optimize', async ({ request, response }) => {
  const selectedColumns = ValidateFields(request, EmployeeMaster);

  if (!selectedColumns['status']) {
    return selectedColumns;
  }

  let query = `SELECT ${selectedColumns['columns']} FROM EmployeeMaster WHERE Id = ${request.body().id}`;
  return response.json(query);
});