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.8 to 0.1.9

dist/src/on.d.ts

4

CHANGELOG.md

@@ -0,1 +1,5 @@

#0.1.9
* Allow where query on data save
#0.1.8

@@ -2,0 +6,0 @@

@@ -11,2 +11,6 @@ import 'reflect-metadata';

}
export interface SaveWhere {
field: string;
value: any;
}
export declare class Query<T extends Model> {

@@ -35,3 +39,3 @@ db: Database;

*/
save(data: T): Promise<any>;
save(data: T, where: SaveWhere): Promise<any>;
/**

@@ -38,0 +42,0 @@ * Save a list of objects to the db

9

dist/on.js

@@ -64,8 +64,9 @@ "use strict";

*/
save(data) {
save(data, where) {
return __awaiter(this, void 0, void 0, function* () {
let statement = [data.id ? 'UPDATE' : 'INSERT INTO', this.table, 'SET ?'].join(' ');
if (data.id)
statement += ' WHERE id = ?';
const queryData = data.id ? [data, data.id] : data;
statement += where ?
(' WHERE' + where.field + ' = ?') : data.id ?
(' WHERE id = ?') : '';
const queryData = where ? [data, where.value] : data.id ? [data, data.id] : data;
return this.db.query(statement, queryData);

@@ -72,0 +73,0 @@ });

import { Model, ModelConstructor } from './model';
import { Query } from './query';
import { Query } from './on';
/** Default MySQL connection option */

@@ -30,3 +30,3 @@ export interface ConnectionOption {

*/
query<T extends Model>(model: ModelConstructor<T>): Query<T>;
on<T extends Model>(model: ModelConstructor<T>): Query<T>;
/**

@@ -37,5 +37,5 @@ * Send prepared sql script to the database

*/
prepare(query: string, extras?: any): Promise<any>;
query(query: string, extras?: any): Promise<any>;
/** Close the connection to the database */
close(): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const query_1 = require("./query");
const on_1 = require("./on");
const mysql = require('promise-mysql');

@@ -23,4 +23,4 @@ /**

*/
query(model) {
return new query_1.Query(this, model);
on(model) {
return new on_1.Query(this, model);
}

@@ -32,3 +32,3 @@ /**

*/
prepare(query, extras) {
query(query, extras) {
return extras ? this.conn.query(query, extras) : this.conn.query(query);

@@ -35,0 +35,0 @@ }

export * from './db';
export * from './helpers';
export * from './model';
export * from './query';
export * from './on';

@@ -9,3 +9,3 @@ "use strict";

__export(require("./model"));
__export(require("./query"));
__export(require("./on"));
//# sourceMappingURL=index.js.map
{
"name": "classql",
"version": "0.1.8",
"version": "0.1.9",
"main": "dist/index.js",

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

@@ -16,2 +16,7 @@ const mysql = require('promise-mysql');

export interface SaveWhere {
field: string;
value: any;
}
export class Query<T extends Model> {

@@ -69,8 +74,11 @@ public db: Database;

*/
public async save(data: T): Promise<any> {
public async save(data: T, where: SaveWhere): Promise<any> {
let statement = [data.id ? 'UPDATE' : 'INSERT INTO', this.table, 'SET ?'].join(' ');
if (data.id) statement += ' WHERE id = ?';
const queryData = data.id ? [data, data.id] : data;
statement += where ?
(' WHERE' + where.field + ' = ?') : data.id ?
(' WHERE id = ?') : '';
const queryData = where ? [data, where.value] : data.id ? [data, data.id] : data;
return this.db.query(statement, queryData);

@@ -77,0 +85,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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