Skip to content

Commit

Permalink
Fix modular select "exported anonymous class type may not be private …
Browse files Browse the repository at this point in the history
…or protected" error
  • Loading branch information
G4brym committed Sep 14, 2024
1 parent e7b9ef8 commit e84ab42
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workers-qb",
"version": "1.6.1",
"version": "1.6.2",
"description": "Zero dependencies Query Builder for Cloudflare Workers",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
30 changes: 15 additions & 15 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
)
}

_parse_arguments(row: DefaultObject): Array<any> {
protected _parse_arguments(row: DefaultObject): Array<any> {
// Raw parameters are placed directly in the query, and keeping them here would result in more parameters that are
// expected in the query and could result in weird results or outright errors when using PostgreSQL
return Object.values(row).filter((value) => {
return !(value instanceof Raw)
})
}

_onConflict(resolution?: string | ConflictTypes | ConflictUpsert): string {
protected _onConflict(resolution?: string | ConflictTypes | ConflictUpsert): string {
if (resolution) {
if (typeof resolution === 'object') {
if (!Array.isArray(resolution.column)) {
Expand All @@ -283,7 +283,7 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
return ''
}

_insert(params: Insert): string {
protected _insert(params: Insert): string {
const rows = []

let data: Array<DefaultObject>
Expand Down Expand Up @@ -347,7 +347,7 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
)
}

_update(params: Update): string {
protected _update(params: Update): string {
const whereParamsLength: number =
typeof params.where === 'object' && !Array.isArray(params.where) && params.where?.params
? Array.isArray(params.where?.params)
Expand Down Expand Up @@ -375,7 +375,7 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
)
}

_delete(params: Delete): string {
protected _delete(params: Delete): string {
return (
`DELETE
FROM ${params.tableName}` +
Expand All @@ -384,7 +384,7 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
)
}

_select(params: SelectAll): string {
protected _select(params: SelectAll): string {
return (
`SELECT ${this._fields(params.fields)}
FROM ${params.tableName}` +
Expand All @@ -398,14 +398,14 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
)
}

_fields(value?: string | Array<string>): string {
protected _fields(value?: string | Array<string>): string {
if (!value) return '*'
if (typeof value === 'string') return value

return value.join(', ')
}

_where(value?: Where): string {
protected _where(value?: Where): string {
if (!value) return ''
let conditions = value

Expand All @@ -422,7 +422,7 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
return ''
}

_join(value?: Join | Array<Join>): string {
protected _join(value?: Join | Array<Join>): string {
if (!value) return ''

if (!Array.isArray(value)) {
Expand All @@ -442,21 +442,21 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
return ' ' + joinQuery.join(' ')
}

_groupBy(value?: string | Array<string>): string {
protected _groupBy(value?: string | Array<string>): string {
if (!value) return ''
if (typeof value === 'string') return ` GROUP BY ${value}`

return ` GROUP BY ${value.join(', ')}`
}

_having(value?: string | Array<string>): string {
protected _having(value?: string | Array<string>): string {
if (!value) return ''
if (typeof value === 'string') return ` HAVING ${value}`

return ` HAVING ${value.join(' AND ')}`
}

_orderBy(value?: string | Array<string> | Record<string, string | OrderTypes>): string {
protected _orderBy(value?: string | Array<string> | Record<string, string | OrderTypes>): string {
if (!value) return ''
if (typeof value === 'string') return ` ORDER BY ${value}`

Expand Down Expand Up @@ -485,19 +485,19 @@ export class QueryBuilder<GenericResultWrapper, IsAsync extends boolean = true>
return ` ORDER BY ${result.join(', ')}`
}

_limit(value?: number): string {
protected _limit(value?: number): string {
if (!value) return ''

return ` LIMIT ${value}`
}

_offset(value?: number): string {
protected _offset(value?: number): string {
if (!value) return ''

return ` OFFSET ${value}`
}

_returning(value?: string | Array<string>): string {
protected _returning(value?: string | Array<string>): string {
if (!value) return ''
if (typeof value === 'string') return ` RETURNING ${value}`

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './databases/do'
export * from './enums'
export * from './interfaces'
export * from './tools'
export * from './logger'
12 changes: 4 additions & 8 deletions src/modularBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { Query, QueryWithExtra } from './tools'

export class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnObject, IsAsync extends boolean = true> {
_debugger = false
private _options: Partial<SelectAll> = {}
private _fetchAll: (params: SelectAll) => QueryWithExtra<GenericResultWrapper, any, IsAsync>
private _fetchOne: (params: SelectOne) => QueryWithExtra<GenericResultWrapper, any, IsAsync>
_options: Partial<SelectAll> = {}
_fetchAll: (params: SelectAll) => QueryWithExtra<GenericResultWrapper, any, IsAsync>
_fetchOne: (params: SelectOne) => QueryWithExtra<GenericResultWrapper, any, IsAsync>

constructor(
options: Partial<SelectAll>,
Expand Down Expand Up @@ -116,11 +116,7 @@ export class SelectBuilder<GenericResultWrapper, GenericResult = DefaultReturnOb
)
}

private _parseArray(
fieldName: string,
option: any,
value: any
): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync> {
_parseArray(fieldName: string, option: any, value: any): SelectBuilder<GenericResultWrapper, GenericResult, IsAsync> {
let val = []
if (!Array.isArray(value)) {
val.push(value)
Expand Down
4 changes: 0 additions & 4 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,3 @@ export class QueryWithExtra<GenericResultWrapper, Result = any, IsAsync extends
export function trimQuery(query: string): string {
return query.replace(/\s\s+/g, ' ')
}

export function defaultLogger<IsAsync extends boolean>(query: RawQuery, meta: QueryLoggerMeta): any {
console.log(`[workers-qb][${meta.duration}ms] ${JSON.stringify(query)}`)
}

0 comments on commit e84ab42

Please sign in to comment.