Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

classql

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

classql - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

CHANGELOG.md

2

package.json
{
"name": "classql",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "bugs": "https://github.com/sorakthunly/classql/issues",

# classql
A light-weight Typescript ORM for MySQL basic CRUD that is `database-model-indepedent`.
A light-weight Typescript ORM for MySQL basic CRUD that is database-model-indepedent.

@@ -8,6 +8,6 @@ ### What it does not do:

### What it does do:
Allows you to decorate your Typescript class with a MySQL `TABLE` or `VIEW` name so you can run basic CRUD operations easily.
Allows you to decorate your Typescript class with a MySQL TABLE or VIEW name so you can run basic CRUD operations easily.
## Installation
Run `npm install --save classql`
`npm install --save classql`

@@ -39,7 +39,4 @@ ## Example Use

/**
* You can enter the database info as a string or an object:
* 'mysql://root:root@localhost/my_database_name?debug=true&timeout=1000000'
*/
export const db = new classql.Database({
// Create MySQL connection:
let db = new classql.Database({
host: 'localhost',

@@ -51,7 +48,11 @@ user: 'root',

// Or:
let db = new classql.Database('mysql://root:root@localhost/my_database_name?debug=true&timeout=1000000');
/** GET */
// This will return a single object or null if no result can be found.
// Returns a single object or null:
await db.on(UserAccount).get({ id: 1 });
// This will return an object with the specified field(s) e.g. { email: 'jd@works.io' }
// Returns an object with any specified field(s) e.g. { email: 'jd@works.io' }
await db.on(UserAccount).get({ id: 1 }, ['email']);

@@ -61,18 +62,19 @@

/** GET ALL */
// These queries will return a list of objects or an empty list if none is found:
// Returns a list of objects or an empty list:
await db.on(UserAccount)>getAll();
await db.on(UserAccount).getAll({ firstName: 'John' });
// You can also pass an offset or limit option
// To pass offset or limit option:
await db.on(UserAccount).getAll({ limit: 10, offset: 20 });
await db.on(UserAccount).getAll({ firstName: 'John' }, { limit: 10, offset: 20 });
await db.on(UserAccount).getAll({ firstName: 'John' }, { limit: 10 });
/** DELETE */
await db.on(UserAccount).delete({ firstName: 'John' });
// Delete any matched field(s):
await db.on(UserAccount).delete({ id: 5 });
/** CREATE OR UPDATE */
// If no id field exists, the query create an object
// Else, an update query is run
// If no id field exists, this method creates an object.
// Otherewise, it will update an existing tuple.
let account = new UserAccount({

@@ -84,2 +86,3 @@ email: 'jd@works.io',

});
let result = await db.on(UserAccount).save(account);

@@ -89,5 +92,5 @@ let id = result.insertId;

// Alternatively, if you want to enter prepared sql statement, just do:
// Alternatively, to enter prepared sql statement just do:
db.query('SELECT * FROM USER_ACCOUNTS WHERE id > 5').then(doSth).catch(doSthElse);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc