Objective SQL


Objective SQL is a fullstack, object-oriented SQL for modern apps; one language and one API over diverse data storage technologies - from in-memory storage, to the client-side IndexedDB, to the server-side database like MySQL.
Speak the same familiar SQL language, this time, with an object-oriented convention for relationships. Or query your data programmatically using a succinct API.
Visit project repo.
Basic Usage
Objective SQL works both in node.js and in the browser. Here's a node.js example:
import { ODB as Client } from '@webqit/objective-sql';
Client.query('SELECT fname, lname FROM users').then(result => {
console.log(result);
});
The Language
Objective SQL is 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;
…but 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.)
The API
Objective SQL also lets us work programmatically using a promise-based API.
Here's the API version of the Basic Usage query we started with:
Client.open().then(async DB => {
let userStore = await DB.open('users');
let result = await userStore.getAll();
console.log(result);
});
Learn more about the API and see just what's possible. (DOCS coming soon.)
Storage
Objective SQL lets us decide between underlying storage technologies without changing code.
While we've used the inbuilt in-memory store in the examples above, we could easily switch to a persistent storage engine, like the IndexedDB that ships with browsers, by simply swiping in the appropriate client in the import
statement…
import {
IDB as Client,
} from '@webqit/objective-sql';
…and the rest of the code can go on "as is".
Learn more about Storage and see just what's possible. (DOCS coming soon.)
Schemas
Objective SQL completely embraces the schema idea of SQL, and offers one simple, universal way to write these schemas that describe your data - whatever the underlying storage engine.
Schema declaration is usually the first step to working with SQL. So, the users
table we've used in the examples above should already have been declared. Here's how easy it is to do that:
(async () => {
const DB = await Client.create([{
name: 'users',
primaryKey: 'id',
autoIncrement: true,
fields: {id: {}, fname: {}, lname: {}, email: {}, age:{type: 'int', default:0},},
uniqueKeys: {email: 'email'},
}, {
name: 'posts',
...
}]);
let userStore = await DB.open('users', 'readwrite');
userStore.addAll([
{fname: 'John', lname: 'Doe', email: 'john.doe@example.com', age: 33},
{fname: 'James', lname: 'Smith', email: 'john.doe@example.com', age: 40},
]);
})();
Learn more about Schemas and see just what's possible. (DOCS coming soon.)