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

ormless

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ormless - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.husky/commit-msg

14

dist/cjs/ormless.d.ts

@@ -1,2 +0,14 @@

export declare class Ormless {
import { AnyColumn, CreateManyArgs, CreateOneArgs, DeleteManyArgs, DeleteOneArgs, FindManyArgs, FindOneArgs, ORMLessMetadata, UpdateManyArgs, UpdateOneArgs } from './ormless.interfaces';
export declare abstract class ORMLessQueryable<DB, META extends ORMLessMetadata<DB>, TB extends keyof DB & string> {
protected abstract table: TB;
selectOne<S extends AnyColumn<DB, TB>>(args: FindOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>>;
selectMany<S extends AnyColumn<DB, TB>>(args: FindManyArgs<DB, TB, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>[]>;
}
export declare abstract class ORMLess<DB, META extends ORMLessMetadata<DB>, TB extends keyof DB & string> extends ORMLessQueryable<DB, META, TB> {
createOne<S extends AnyColumn<DB, TB>>(args: CreateOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<DB, TB, S>>>;
createMany<S extends AnyColumn<DB, TB>>(args: CreateManyArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<DB, TB, S>>[]>;
updateOne<S extends AnyColumn<DB, TB>>(args: UpdateOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>>;
updateMany<S extends AnyColumn<DB, TB>>(args: UpdateManyArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>[]>;
deleteOne<S extends AnyColumn<DB, TB>>(args: DeleteOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>>;
deleteMany<S extends AnyColumn<DB, TB>>(args: DeleteManyArgs<DB, TB, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>[]>;
}
"use strict";
/* eslint-disable @typescript-eslint/no-explicit-any */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Ormless = void 0;
class Ormless {
exports.ORMLess = exports.ORMLessQueryable = void 0;
const ormless_exceptions_1 = require("./ormless.exceptions");
// TODO, overload typescript functions to allow return debug ? qb.compile() : qb.executeTakeFirstOrThrow();
class ORMLessQueryable {
async selectOne(args) {
const { db, debug = false, where, select } = args;
let qb = db.selectFrom(this.table).select(select);
const whereKeys = Object.keys(where);
for (const [lfs, rhs] of Object.entries(where[whereKeys[0]])) {
qb = qb.where(lfs, '=', rhs);
}
return qb.executeTakeFirstOrThrow();
}
async selectMany(args) {
const { db, debug = false, where, select, limit, offset } = args;
if (!select.length) {
return [];
}
let qb = db.selectFrom(this.table).select(select);
for (const [lfs, op, rhs] of where) {
qb = qb.where(lfs, op, rhs);
}
qb = qb.limit(limit).offset(offset);
return qb.execute();
}
}
exports.Ormless = Ormless;
exports.ORMLessQueryable = ORMLessQueryable;
class ORMLess extends ORMLessQueryable {
async createOne(args) {
const { db, debug = false, data, select = [] } = args;
const qb = db
.insertInto(this.table)
.values(data)
.returning(select);
return qb.executeTakeFirstOrThrow();
}
async createMany(args) {
const { db, debug = false, data, select = [] } = args;
if (!data.length) {
return [];
}
const qb = db
.insertInto(this.table)
.values(data)
.returning(select);
return qb.execute();
}
async updateOne(args) {
const { db, debug = false, where, data, select = [] } = args;
const whereKeys = Object.keys(where);
if (whereKeys.length !== 1) {
throw new ormless_exceptions_1.ORMLessMissingWhereClasueException();
}
let qb = db
.updateTable(this.table)
.set(data)
.returning(select);
for (const [lfs, rhs] of Object.entries(where[whereKeys[0]])) {
qb = qb.where(lfs, '=', rhs);
}
return qb.executeTakeFirstOrThrow();
}
async updateMany(args) {
const { db, debug = false, where, data, select = [] } = args;
if (!data.length) {
return [];
}
if (!where.length) {
throw new ormless_exceptions_1.ORMLessMissingWhereClasueException();
}
let qb = db
.updateTable(this.table)
.set(data)
.returning(select);
for (const [lfs, op, rhs] of where) {
qb = qb.where(lfs, op, rhs);
}
return qb.execute();
}
async deleteOne(args) {
const { db, debug = false, where, select = [] } = args;
const whereKeys = Object.keys(where);
if (whereKeys.length !== 1) {
throw new ormless_exceptions_1.ORMLessMissingWhereClasueException();
}
let qb = db.deleteFrom(this.table).returning(select);
for (const [lfs, rhs] of Object.entries(where[whereKeys[0]])) {
qb = qb.where(lfs, '=', rhs);
}
return qb.executeTakeFirstOrThrow();
}
async deleteMany(args) {
const { db, debug = false, where, select = [] } = args;
if (!where.length) {
throw new ormless_exceptions_1.ORMLessMissingWhereClasueException();
}
let qb = db.deleteFrom(this.table).returning(select);
for (const [lfs, op, rhs] of where) {
qb = qb.where(lfs, op, rhs);
}
return qb.execute();
}
}
exports.ORMLess = ORMLess;

@@ -1,2 +0,14 @@

export declare class Ormless {
import { AnyColumn, CreateManyArgs, CreateOneArgs, DeleteManyArgs, DeleteOneArgs, FindManyArgs, FindOneArgs, ORMLessMetadata, UpdateManyArgs, UpdateOneArgs } from './ormless.interfaces';
export declare abstract class ORMLessQueryable<DB, META extends ORMLessMetadata<DB>, TB extends keyof DB & string> {
protected abstract table: TB;
selectOne<S extends AnyColumn<DB, TB>>(args: FindOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>>;
selectMany<S extends AnyColumn<DB, TB>>(args: FindManyArgs<DB, TB, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>[]>;
}
export declare abstract class ORMLess<DB, META extends ORMLessMetadata<DB>, TB extends keyof DB & string> extends ORMLessQueryable<DB, META, TB> {
createOne<S extends AnyColumn<DB, TB>>(args: CreateOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<DB, TB, S>>>;
createMany<S extends AnyColumn<DB, TB>>(args: CreateManyArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<DB, TB, S>>[]>;
updateOne<S extends AnyColumn<DB, TB>>(args: UpdateOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>>;
updateMany<S extends AnyColumn<DB, TB>>(args: UpdateManyArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>[]>;
deleteOne<S extends AnyColumn<DB, TB>>(args: DeleteOneArgs<DB, TB, META, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").NonEmptySingleResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>>;
deleteMany<S extends AnyColumn<DB, TB>>(args: DeleteManyArgs<DB, TB, S>): Promise<import("kysely/dist/cjs/query-builder/type-utils").ManyResultRowType<import("kysely/dist/cjs/parser/select-parser").Selection<import("kysely/dist/cjs/parser/table-parser").TableExpressionDatabaseType<DB, TB>, import("kysely/dist/cjs/parser/table-parser").ExtractAliasFromTableExpression<DB, TB>, S>>[]>;
}

@@ -1,2 +0,102 @@

export class Ormless {
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ORMLessMissingWhereClasueException } from './ormless.exceptions';
// TODO, overload typescript functions to allow return debug ? qb.compile() : qb.executeTakeFirstOrThrow();
export class ORMLessQueryable {
async selectOne(args) {
const { db, debug = false, where, select } = args;
let qb = db.selectFrom(this.table).select(select);
const whereKeys = Object.keys(where);
for (const [lfs, rhs] of Object.entries(where[whereKeys[0]])) {
qb = qb.where(lfs, '=', rhs);
}
return qb.executeTakeFirstOrThrow();
}
async selectMany(args) {
const { db, debug = false, where, select, limit, offset } = args;
if (!select.length) {
return [];
}
let qb = db.selectFrom(this.table).select(select);
for (const [lfs, op, rhs] of where) {
qb = qb.where(lfs, op, rhs);
}
qb = qb.limit(limit).offset(offset);
return qb.execute();
}
}
export class ORMLess extends ORMLessQueryable {
async createOne(args) {
const { db, debug = false, data, select = [] } = args;
const qb = db
.insertInto(this.table)
.values(data)
.returning(select);
return qb.executeTakeFirstOrThrow();
}
async createMany(args) {
const { db, debug = false, data, select = [] } = args;
if (!data.length) {
return [];
}
const qb = db
.insertInto(this.table)
.values(data)
.returning(select);
return qb.execute();
}
async updateOne(args) {
const { db, debug = false, where, data, select = [] } = args;
const whereKeys = Object.keys(where);
if (whereKeys.length !== 1) {
throw new ORMLessMissingWhereClasueException();
}
let qb = db
.updateTable(this.table)
.set(data)
.returning(select);
for (const [lfs, rhs] of Object.entries(where[whereKeys[0]])) {
qb = qb.where(lfs, '=', rhs);
}
return qb.executeTakeFirstOrThrow();
}
async updateMany(args) {
const { db, debug = false, where, data, select = [] } = args;
if (!data.length) {
return [];
}
if (!where.length) {
throw new ORMLessMissingWhereClasueException();
}
let qb = db
.updateTable(this.table)
.set(data)
.returning(select);
for (const [lfs, op, rhs] of where) {
qb = qb.where(lfs, op, rhs);
}
return qb.execute();
}
async deleteOne(args) {
const { db, debug = false, where, select = [] } = args;
const whereKeys = Object.keys(where);
if (whereKeys.length !== 1) {
throw new ORMLessMissingWhereClasueException();
}
let qb = db.deleteFrom(this.table).returning(select);
for (const [lfs, rhs] of Object.entries(where[whereKeys[0]])) {
qb = qb.where(lfs, '=', rhs);
}
return qb.executeTakeFirstOrThrow();
}
async deleteMany(args) {
const { db, debug = false, where, select = [] } = args;
if (!where.length) {
throw new ORMLessMissingWhereClasueException();
}
let qb = db.deleteFrom(this.table).returning(select);
for (const [lfs, op, rhs] of where) {
qb = qb.where(lfs, op, rhs);
}
return qb.execute();
}
}

40

package.json
{
"name": "ormless",
"version": "0.0.1",
"version": "0.0.2",
"bin": "./bin/ormless",
"description": "Type safe SQL shortcuts based on kysely",

@@ -14,8 +15,13 @@ "main": "dist/cjs/index.js",

"scripts": {
"clean": "rm -rf dist && rm -rf test/dist",
"prebuild": "npm run clean",
"prebuild": "rm -rf dist",
"postbuild": "./scripts/postbuild",
"build": "npm run build:esm && npm run build:cjs",
"postbuild": "./scripts/postbuild.sh",
"build:esm": "tsc -p tsconfig-esm.json",
"build:cjs": "tsc -p tsconfig-cjs.json"
"build:cjs": "tsc -p tsconfig-cjs.json",
"dev": "node -r ts-node/register -r dotenv/config scratchpad/demo",
"example": "node -r ts-node/register -r dotenv/config example/index",
"example:pull": "node -r ts-node/register -r dotenv/config example/introspect",
"db:pull-pg-metadata": "node -r ts-node/register -r dotenv/config scratchpad/introspect-pg-metadata",
"db:generate": "node -r ts-node/register -r dotenv/config src/cli",
"prepare": "husky install"
},

@@ -25,10 +31,26 @@ "author": "Michael Li",

"dependencies": {
"change-case": "4.1.2",
"kysely": "0.3.9"
"change-case": "^4.1.2"
},
"peerDependencies": {
"kysely": "^0.3.9"
},
"devDependencies": {
"type-fest": "2.3.4",
"@commitlint/cli": "^13.2.0",
"@commitlint/config-conventional": "^13.2.0",
"@types/change-case": "^2.3.1",
"@types/dotenv": "^8.2.0",
"@types/node": "^16.10.2",
"pg": "8.7.1"
"@types/prettier": "^2.4.1",
"@types/yargs": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"handlebars": "^4.7.7",
"husky": "^7.0.2",
"pg": "^8.7.1",
"prettier": "^2.4.1",
"ts-node": "^10.2.1",
"yargs": "^17.2.1"
}
}
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