3.3.3 • Published 10 months ago

fql-toolkit v3.3.3

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

FQL Toolkit Library

A lightweight and flexible JavaScript toolkit library for Form Query Language (FQL) that provides a fluent API for building and executing FQL queries.

📦 Installation

# Using npm
npm install fql-toolkit

🔧 Quick Start

import { FQL } from 'fql-toolkit';

// Initialize the client
const fql = new FQL({
  url: 'https://api.example.com',
  token: 'FQL USER TOKEN HERE'
});

// Create a form
await fql.createForm('users')
  .addDataDefinition({name: 'name', type: 'text'})
  .addDataDefinition({name: 'age', type: 'number'})
  .addDataDefinition({name: 'email', type: 'text'})
  .execute();

// Show forms
await fql.showForms()
  .setForm("users")
  .execute()
  .then(response => console.log(response.output))

// Insert data
await fql.createNew('users')
  .setValue('John Doe')
  .setValue(30)
  .setValue('john@example.com')
  .execute();

// Show data
await fql.getCase('users')
  .addFields('name', 'age')
  .execute()
  .then(response => console.log(response.output))

// Remove forms
await fql.removeForms()
  .setForm("users")
  .execute();

📖 Documentation

Initialization

const fql = new FQL({
  url: string;     // Required: API endpoint
  token: string;   // Required: FQL token
});

Creating Forms

// Basic form creation
await fql.createForm('employees')
  .addDataDefinition({name: 'name', type: 'text'})
  .addDataDefinition({name: 'salary', type: 'number'})
  .execute();

// Getting the FQL without executing
const formQuery = fql.createForm('employees')
  .addDataDefinition({name: 'name', type: 'text'})
  .getFQL();
// Result: "create form employees(name text, salary number)"

Inserting Data

// Single record insertion
await fql.createData('employees')
  .setValue('John Doe')
  .setValue(50000)
  .execute();

// Get FQL without executing
const dataQuery = fql.createData('employees')
  .setValue('Jane Smith')
  .setValue(60000)
  .getFQL();
// Result: "create employees('Jane Smith', 60000)"

Showing Forms

// All forms
const allForms = fql.showForms()
// Specific form
const specificForm = fql.showForms().setForm("People")
// List of forms
const formList =  fql.showForms().setForm("People").setForm("Countries")
// Equivalent to fql.showForms().setForms(["People", "Countries"]")

// Get FQL without executing
allForms.getFql() // Result: "show forms"
specificForm.getFql() // Result: "show forms People"
formList.getFql() // Result: "show forms People, Countries"

// Show all forms
await allForms.execute()
// Show a specific form
await specificForm.execute()
// Show list of forms
await formList.execute()

Removing Forms

// All forms
const allForms = fql.removeForms()
// Specific form
const specificForm = fql.removeForms().setForm("People")
// List of forms
const formList =  fql.removeForms().setForm("People").setForm("Countries")
// Equivalent to fql.removeForms().setForms(["People", "Countries"]")

// Get FQL without executing
allForms.getFql() // Result: "show forms"
specificForm.getFql() // Result: "show forms People"
formList.getFql() // Result: "show forms People, Countries"

// Show all forms
await allForms.execute()
// Show a specific form
await specificForm.execute()
// Show list of forms
await formList.execute()

Error Handling

try {
  const result = await fql.createData('employees')
    .setValue('John Doe')
    .setValue('invalid_salary') // Wrong type
    .execute();
} catch (error) {
  if (error instanceof FQLError) {
    console.error('FQL Error:', error.message);
    console.error('Query:', error.query);
    console.error('Code:', error.code);
  }
}

🎯 Examples

Complex Form Creation

const form = await fql.createForm('products')
  .addDataDefinition({name: 'id', type: 'number'})
  .addDataDefinition({name: 'name', type: 'text'})
  .addDataDefinition({name: 'description', type: 'text'})
  .addDataDefinition({name: 'price', type: 'number'})
  .addDataDefinition({name: 'inStock', type: 'boolean'})
  .addDataDefinition({name: 'categories', type: 'array'})
  .addDataDefinition({name: 'created', type: 'date'})
  .execute();

Batch Data Insertion

const products = [
  ['Product A', 29.99, true],
  ['Product B', 49.99, false],
  ['Product C', 99.99, true]
];

for (const [name, price, inStock] of products) {
  await fql.createData('products')
    .setValue(name)
    .setValue(price)
    .setValue(inStock)
    .execute();
}

🔍 API Reference

FQL Class

MethodDescriptionParametersReturns
createFormCreates a FQLForm builderformName: stringFQLFormBuilder
createNewCreates a FQLData builderformName: stringFQLDataBuilder
showFormsCreate a FQLShowForms builderNoneFQLShowFormsBuilder
removeFormsCreate a FQLRemoveForms builderNoneFQLRemoveFormsBuilder
executeFQLExecutes raw FQLquery: stringPromise<any>

FQLFormBuilder Class

MethodDescriptionParametersReturns
addDataDefinitionAdds a data definition field{name: string, type: string, notNull: boolean = false, unique: boolean: false}FQLFormBuilder
addDataReferenceAdds a data reference field{name: string, cardinality: list = [0, 1], path: list, totally: boolean = false, unique: boolean = false}FQLFormBuilder
createExecutes the queryNonePromise<any>
getFQLGets the FQL stringquery: stringstring

FQLDataBuilder Class

MethodDescriptionParametersReturns
setValueAdds a valuevalue: anyFQLDataBuilder
createExecutes the queryNonePromise<any>
getFQLGets the FQL stringquery: stringstring

FQLShowFormsBuilder Class

MethodDescriptionParametersReturns
setFormAdd a formvalue: stringFQLShowFormsBuilder
setFormsAdd a form listvalue: [string]FQLShowFormsBuilder
createExecutes the queryNonePromise<any>
getFQLGets the FQL stringquery: stringstring

FQLRemoveFormsBuilder Class

MethodDescriptionParametersReturns
setFormAdd a formvalue: stringFQLRemoveFormsBuilder
setFormsAdd a form listvalue: [string]FQLRemoveFormsBuilder
createExecutes the queryNonePromise<any>
getFQLGets the FQL stringquery: stringstring
3.3.1

10 months ago

3.1.1

10 months ago

3.1.0

10 months ago

3.3.3

10 months ago

3.3.2

10 months ago

1.1.4

10 months ago

1.0.4

10 months ago

2.10.1

10 months ago

2.2.0

10 months ago

2.5.0

10 months ago

2.10.0

10 months ago

2.4.0

10 months ago

2.7.0

10 months ago

2.6.0

10 months ago

2.9.0

10 months ago

2.8.0

10 months ago

2.1.0

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago