@webqit/objective-sql
v0.2.76
Published
The Succinct, fullstack SQL for modern web apps.
Downloads
10
Maintainers
Readme
Linked QL
The object-oriented, adaptive SQL client for modern apps - query anything from the plain JSON object, to the client-side IndexedDB, to the server-side DB.
Overview
Linked QL is a query client that wraps powerful concepts in a simple, succint API.
- It lets you query different types of databases using one consistent syntax and API.
- Both SQL databases (like MySQL, PostgreSQL) and client-side, non-SQL databases (like IndexedDB).
- One syntax and API to rule them all!
- It implements a superset of the SQL language that lets you access relationships without constructing JOINS.
- Goodbye query complexity!
- Goodbye ORMs!
Take a one-minute overview of Objective SQL.
Basic Usage
Obtain an Objective SQL query client for your target database:
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);
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;
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:
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); });
Other methods give us a programmatic way to manipulate or query the database. (Docs coming soon.)
- The
client.createDatabase()
andclient.createDatabaseIfNotExists()
methods. (Returning aDatabase
instance (database
).) - The
client.dropDatabase()
andclient.dropDatabaseIfExists()
methods. - The
client.databases()
method - for listing databases, and theclient.database(name)
method - for obtaining aDatabase
instance (database
). - The
database.createTable()
,database.alterTable()
, anddatabase.dropTable()
methods. - The
database.tables()
method - for listing tables, thedatabase.table(name)
method - for obtaining aTable
instance (table
). - The
table.getAll()
method - for listing entries, thetable.get(id)
method - for obtaining an entry, thetable.count()
method - for count. - The
table.addAll()
andtable.add()
methods. - The
table.putAll()
andtable.put()
methods. - The
table.deleteAll()
andtable.delete()
methods.
- The
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
Issues
To report bugs or request features, please submit an issue to this repository.
License
MIT.