Comparing version 0.0.1 to 0.0.2
@@ -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(); | ||
} | ||
} |
{ | ||
"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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
133464
69
3340
1
34
17
1
5
1
+ Addedkysely@0.3.11(transitive)
- Removedkysely@0.3.9
- Removedkysely@0.3.9(transitive)
Updatedchange-case@^4.1.2