@webqit/objective-sql

0.2.75 • Public • Published

Objective SQL

NPM version NPM downloads Coverage Status Patreon donate button

The object-oriented, adaptive SQL for modern apps - query anything from the plain JSON object, to the client-side IndexedDB, to the server-side DB.

Overview

Objective SQL is a query client that wraps powerful concepts in a simple, succint API.

  1. It lets you query different types of databases using one consistent syntax and API.
    1. Both SQL databases (like MySQL, PostgreSQL) and client-side, non-SQL databases (like IndexedDB).
    2. One syntax and API to rule them all!
  2. It implements a superset of the SQL language that lets you access relationships without constructing JOINS.
    1. Goodbye query complexity!
    2. Goodbye ORMs!

Take a one-minute overview of Objective SQL.

Basic Usage

Obtain an Objective SQL query client for your target database:

  1. For SQL databases, import and instantiate the SQL language driver. (You'll pass in the name of an appropriate database connection driver that works for your database.)

    // Import SQL
    import { SQL } from '@webqit/objective-sql';
    
    // Using the 'mysql2' connector (npm install mysql2)
    const connectionDriver = 'mysql2';
    const connectionParams = {
        host: '127.0.0.1',
        user: 'root',
        password: '',
    };
    
    // Create an instance by calling .connect().
    const client = SQL.connect(connectionDriver, connectionParams);
    
    // Or by using the 'new' keyword.
    const client = new SQL(connectionDriver, connectionParams);
  2. For the client-side IndexedDB database, import and instantiate the IDB language driver.

    IndexedDB is a low-level API for client-side storage.

    // Import IDB
    import { IDB } from '@webqit/objective-sql';
    
    // Create an instance.
    const client = new IDB;
  3. To work with Objective SQL's in-memory object storage, import and instantiate the ODB language driver.

    This is an environment-agnostic in-memory store.

    // Import IDB
    import { ODB } from '@webqit/objective-sql';
    
    // Create an instance.
    const client = new ODB;

All client instances above implement the same interface:

  1. The client.query() method lets you run any SQL query on your database.

    // Run a query
    client.query('SELECT fname, lname FROM users').then(result => {
        console.log(result);
    });
  2. Other methods give us a programmatic way to manipulate or query the database. (Docs coming soon.)

    1. The client.createDatabase() and client.createDatabaseIfNotExists() methods. (Returning a Database instance (database).)
    2. The client.dropDatabase() and client.dropDatabaseIfExists() methods.
    3. The client.databases() method - for listing databases, and the client.database(name) method - for obtaining a Database instance (database).
    4. The database.createTable(), database.alterTable(), and database.dropTable() methods.
    5. The database.tables() method - for listing tables, the database.table(name) method - for obtaining a Table instance (table).
    6. The table.getAll() method - for listing entries, the table.get(id) method - for obtaining an entry, the table.count() method - for count.
    7. The table.addAll() and table.add() methods.
    8. The table.putAll() and table.put() methods.
    9. The table.deleteAll() and table.delete() methods.

Learn more about the API. (DOCS coming soon.)

What About Relationships? - The Language

Objective SQL is a superset of the same familiar, powerful SQL language you know...

SELECT post_title, users.fname AS author_name FROM posts
LEFT JOIN users ON users.id = posts.author_id;

...with an object-oriented syntax for relationships, built into the language...

SELECT post_title, author_id->fname AS author_name FROM posts;

...and that's SQL without the query complexity!

Learn more about the language and see just what's possible with the arrow syntax. (DOCS coming soon.)

Documentation

Objective SQL Documentions

Issues

To report bugs or request features, please submit an issue to this repository.

License

MIT.

Package Sidebar

Install

npm i @webqit/objective-sql

Weekly Downloads

0

Version

0.2.75

License

MIT

Unpacked Size

405 kB

Total Files

88

Last publish

Collaborators

  • ox-harris