Updates
This commit is contained in:
parent
613962a925
commit
af6b44ffbe
6
dist/index.d.ts
vendored
6
dist/index.d.ts
vendored
@ -3,11 +3,17 @@ import DbInsert from "./lib/sqlite/db-insert";
|
|||||||
import DbSelect from "./lib/sqlite/db-select";
|
import DbSelect from "./lib/sqlite/db-select";
|
||||||
import DbSQL from "./lib/sqlite/db-sql";
|
import DbSQL from "./lib/sqlite/db-sql";
|
||||||
import DbUpdate from "./lib/sqlite/db-update";
|
import DbUpdate from "./lib/sqlite/db-update";
|
||||||
|
import grabDbSchema from "./utils/grab-db-schema";
|
||||||
|
import grabJoinFieldsFromQueryObject from "./utils/grab-join-fields-from-query-object";
|
||||||
declare const BunSQLite: {
|
declare const BunSQLite: {
|
||||||
readonly select: typeof DbSelect;
|
readonly select: typeof DbSelect;
|
||||||
readonly insert: typeof DbInsert;
|
readonly insert: typeof DbInsert;
|
||||||
readonly update: typeof DbUpdate;
|
readonly update: typeof DbUpdate;
|
||||||
readonly delete: typeof DbDelete;
|
readonly delete: typeof DbDelete;
|
||||||
readonly sql: typeof DbSQL;
|
readonly sql: typeof DbSQL;
|
||||||
|
readonly utils: {
|
||||||
|
readonly grab_db_schema: typeof grabDbSchema;
|
||||||
|
readonly grab_join_fields_from_query_object: typeof grabJoinFieldsFromQueryObject;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
export default BunSQLite;
|
export default BunSQLite;
|
||||||
|
|||||||
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -3,11 +3,17 @@ import DbInsert from "./lib/sqlite/db-insert";
|
|||||||
import DbSelect from "./lib/sqlite/db-select";
|
import DbSelect from "./lib/sqlite/db-select";
|
||||||
import DbSQL from "./lib/sqlite/db-sql";
|
import DbSQL from "./lib/sqlite/db-sql";
|
||||||
import DbUpdate from "./lib/sqlite/db-update";
|
import DbUpdate from "./lib/sqlite/db-update";
|
||||||
|
import grabDbSchema from "./utils/grab-db-schema";
|
||||||
|
import grabJoinFieldsFromQueryObject from "./utils/grab-join-fields-from-query-object";
|
||||||
const BunSQLite = {
|
const BunSQLite = {
|
||||||
select: DbSelect,
|
select: DbSelect,
|
||||||
insert: DbInsert,
|
insert: DbInsert,
|
||||||
update: DbUpdate,
|
update: DbUpdate,
|
||||||
delete: DbDelete,
|
delete: DbDelete,
|
||||||
sql: DbSQL,
|
sql: DbSQL,
|
||||||
|
utils: {
|
||||||
|
grab_db_schema: grabDbSchema,
|
||||||
|
grab_join_fields_from_query_object: grabJoinFieldsFromQueryObject,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
export default BunSQLite;
|
export default BunSQLite;
|
||||||
|
|||||||
5
dist/types/index.d.ts
vendored
5
dist/types/index.d.ts
vendored
@ -1336,3 +1336,8 @@ export type BunSQLiteConfigReturn = {
|
|||||||
* Default fields automatically suggested for new tables.
|
* Default fields automatically suggested for new tables.
|
||||||
*/
|
*/
|
||||||
export declare const DefaultFields: BUN_SQLITE_FieldSchemaType[];
|
export declare const DefaultFields: BUN_SQLITE_FieldSchemaType[];
|
||||||
|
export type BunSQLiteQueryFieldValues<F extends string = string, T extends string = string> = {
|
||||||
|
field: F;
|
||||||
|
table?: T;
|
||||||
|
};
|
||||||
|
export type QueryRawValueType = string | number | null | undefined;
|
||||||
|
|||||||
1
dist/utils/grab-db-schema.d.ts
vendored
Normal file
1
dist/utils/grab-db-schema.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default function grabDbSchema(): Promise<import("../types").BUN_SQLITE_DatabaseSchemaType>;
|
||||||
5
dist/utils/grab-db-schema.js
vendored
Normal file
5
dist/utils/grab-db-schema.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import init from "../functions/init";
|
||||||
|
export default async function grabDbSchema() {
|
||||||
|
const { dbSchema } = await init();
|
||||||
|
return dbSchema;
|
||||||
|
}
|
||||||
6
dist/utils/grab-join-fields-from-query-object.d.ts
vendored
Normal file
6
dist/utils/grab-join-fields-from-query-object.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import type { BunSQLiteQueryFieldValues, ServerQueryParam } from "../types";
|
||||||
|
type Params<Q extends Record<string, any> = Record<string, any>> = {
|
||||||
|
query: ServerQueryParam<Q>;
|
||||||
|
};
|
||||||
|
export default function grabJoinFieldsFromQueryObject<Q extends Record<string, any> = Record<string, any>, F extends string = string, T extends string = string>({ query }: Params<Q>): BunSQLiteQueryFieldValues<F, T>[];
|
||||||
|
export {};
|
||||||
45
dist/utils/grab-join-fields-from-query-object.js
vendored
Normal file
45
dist/utils/grab-join-fields-from-query-object.js
vendored
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
export default function grabJoinFieldsFromQueryObject({ query }) {
|
||||||
|
const fields_values = [];
|
||||||
|
const new_query = _.cloneDeep(query);
|
||||||
|
if (new_query.join) {
|
||||||
|
for (let i = 0; i < new_query.join.length; i++) {
|
||||||
|
const join = new_query.join[i];
|
||||||
|
if (!join)
|
||||||
|
continue;
|
||||||
|
if (Array.isArray(join)) {
|
||||||
|
for (let i = 0; i < join.length; i++) {
|
||||||
|
const single_join = join[i];
|
||||||
|
fields_values.push(...grabSingleJoinData({
|
||||||
|
join: single_join,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fields_values.push(...grabSingleJoinData({
|
||||||
|
join: join,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fields_values;
|
||||||
|
}
|
||||||
|
function grabSingleJoinData({ join, }) {
|
||||||
|
let values = [];
|
||||||
|
const join_select_fields = join?.selectFields;
|
||||||
|
if (join_select_fields) {
|
||||||
|
for (let i = 0; i < join_select_fields.length; i++) {
|
||||||
|
const select_field = join_select_fields[i];
|
||||||
|
if (select_field) {
|
||||||
|
const value = join.match;
|
||||||
|
values.push({
|
||||||
|
field: typeof select_field == "object"
|
||||||
|
? String(select_field.field)
|
||||||
|
: String(select_field),
|
||||||
|
table: join.tableName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
}
|
||||||
6
dist/utils/query-value-parser.d.ts
vendored
Normal file
6
dist/utils/query-value-parser.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import type { QueryRawValueType, ServerQueryObjectValue } from "../types";
|
||||||
|
type Params = {
|
||||||
|
query_value: ServerQueryObjectValue;
|
||||||
|
};
|
||||||
|
export default function queryValueParser({ query_value, }: Params): QueryRawValueType | QueryRawValueType[];
|
||||||
|
export {};
|
||||||
21
dist/utils/query-value-parser.js
vendored
Normal file
21
dist/utils/query-value-parser.js
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
export default function queryValueParser({ query_value, }) {
|
||||||
|
if (typeof query_value == "string" || typeof query_value == "number") {
|
||||||
|
return query_value;
|
||||||
|
}
|
||||||
|
if (Array.isArray(query_value)) {
|
||||||
|
let values = [];
|
||||||
|
for (let i = 0; i < query_value.length; i++) {
|
||||||
|
const single_value = query_value[i];
|
||||||
|
if (single_value) {
|
||||||
|
const single_parsed_value = queryValueParser({
|
||||||
|
query_value: single_value,
|
||||||
|
});
|
||||||
|
if (!Array.isArray(single_parsed_value)) {
|
||||||
|
values.push(single_parsed_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
return query_value?.value;
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bun-sqlite",
|
"name": "@moduletrace/bun-sqlite",
|
||||||
"version": "1.0.36",
|
"version": "1.0.37",
|
||||||
"description": "SQLite manager for Bun",
|
"description": "SQLite manager for Bun",
|
||||||
"author": "Benjamin Toby",
|
"author": "Benjamin Toby",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import DbInsert from "./lib/sqlite/db-insert";
|
|||||||
import DbSelect from "./lib/sqlite/db-select";
|
import DbSelect from "./lib/sqlite/db-select";
|
||||||
import DbSQL from "./lib/sqlite/db-sql";
|
import DbSQL from "./lib/sqlite/db-sql";
|
||||||
import DbUpdate from "./lib/sqlite/db-update";
|
import DbUpdate from "./lib/sqlite/db-update";
|
||||||
|
import grabDbSchema from "./utils/grab-db-schema";
|
||||||
|
import grabJoinFieldsFromQueryObject from "./utils/grab-join-fields-from-query-object";
|
||||||
|
|
||||||
const BunSQLite = {
|
const BunSQLite = {
|
||||||
select: DbSelect,
|
select: DbSelect,
|
||||||
@ -10,6 +12,10 @@ const BunSQLite = {
|
|||||||
update: DbUpdate,
|
update: DbUpdate,
|
||||||
delete: DbDelete,
|
delete: DbDelete,
|
||||||
sql: DbSQL,
|
sql: DbSQL,
|
||||||
|
utils: {
|
||||||
|
grab_db_schema: grabDbSchema,
|
||||||
|
grab_join_fields_from_query_object: grabJoinFieldsFromQueryObject,
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default BunSQLite;
|
export default BunSQLite;
|
||||||
|
|||||||
@ -1522,3 +1522,13 @@ export const DefaultFields: BUN_SQLITE_FieldSchemaType[] = [
|
|||||||
"The time when the record was updated. (Unix Timestamp)",
|
"The time when the record was updated. (Unix Timestamp)",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export type BunSQLiteQueryFieldValues<
|
||||||
|
F extends string = string,
|
||||||
|
T extends string = string,
|
||||||
|
> = {
|
||||||
|
field: F;
|
||||||
|
table?: T;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type QueryRawValueType = string | number | null | undefined;
|
||||||
|
|||||||
6
src/utils/grab-db-schema.ts
Normal file
6
src/utils/grab-db-schema.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import init from "../functions/init";
|
||||||
|
|
||||||
|
export default async function grabDbSchema() {
|
||||||
|
const { dbSchema } = await init();
|
||||||
|
return dbSchema;
|
||||||
|
}
|
||||||
73
src/utils/grab-join-fields-from-query-object.ts
Normal file
73
src/utils/grab-join-fields-from-query-object.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
import type {
|
||||||
|
BunSQLiteQueryFieldValues,
|
||||||
|
ServerQueryParam,
|
||||||
|
ServerQueryParamsJoin,
|
||||||
|
} from "../types";
|
||||||
|
|
||||||
|
type Params<Q extends Record<string, any> = Record<string, any>> = {
|
||||||
|
query: ServerQueryParam<Q>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function grabJoinFieldsFromQueryObject<
|
||||||
|
Q extends Record<string, any> = Record<string, any>,
|
||||||
|
F extends string = string,
|
||||||
|
T extends string = string,
|
||||||
|
>({ query }: Params<Q>): BunSQLiteQueryFieldValues<F, T>[] {
|
||||||
|
const fields_values: BunSQLiteQueryFieldValues<F, T>[] = [];
|
||||||
|
const new_query = _.cloneDeep(query);
|
||||||
|
|
||||||
|
if (new_query.join) {
|
||||||
|
for (let i = 0; i < new_query.join.length; i++) {
|
||||||
|
const join = new_query.join[i];
|
||||||
|
if (!join) continue;
|
||||||
|
|
||||||
|
if (Array.isArray(join)) {
|
||||||
|
for (let i = 0; i < join.length; i++) {
|
||||||
|
const single_join = join[i];
|
||||||
|
fields_values.push(
|
||||||
|
...(grabSingleJoinData({
|
||||||
|
join: single_join as ServerQueryParamsJoin,
|
||||||
|
}) as BunSQLiteQueryFieldValues<F, T>[]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fields_values.push(
|
||||||
|
...(grabSingleJoinData({
|
||||||
|
join: join as ServerQueryParamsJoin,
|
||||||
|
}) as BunSQLiteQueryFieldValues<F, T>[]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fields_values;
|
||||||
|
}
|
||||||
|
|
||||||
|
function grabSingleJoinData({
|
||||||
|
join,
|
||||||
|
}: {
|
||||||
|
join: ServerQueryParamsJoin;
|
||||||
|
}): BunSQLiteQueryFieldValues[] {
|
||||||
|
let values: BunSQLiteQueryFieldValues[] = [];
|
||||||
|
|
||||||
|
const join_select_fields = join?.selectFields;
|
||||||
|
|
||||||
|
if (join_select_fields) {
|
||||||
|
for (let i = 0; i < join_select_fields.length; i++) {
|
||||||
|
const select_field = join_select_fields[i];
|
||||||
|
if (select_field) {
|
||||||
|
const value = join.match;
|
||||||
|
values.push({
|
||||||
|
field:
|
||||||
|
typeof select_field == "object"
|
||||||
|
? String(select_field.field)
|
||||||
|
: String(select_field),
|
||||||
|
table: join.tableName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
33
src/utils/query-value-parser.ts
Normal file
33
src/utils/query-value-parser.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import type { QueryRawValueType, ServerQueryObjectValue } from "../types";
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
query_value: ServerQueryObjectValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function queryValueParser({
|
||||||
|
query_value,
|
||||||
|
}: Params): QueryRawValueType | QueryRawValueType[] {
|
||||||
|
if (typeof query_value == "string" || typeof query_value == "number") {
|
||||||
|
return query_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(query_value)) {
|
||||||
|
let values: QueryRawValueType[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < query_value.length; i++) {
|
||||||
|
const single_value = query_value[i];
|
||||||
|
if (single_value) {
|
||||||
|
const single_parsed_value = queryValueParser({
|
||||||
|
query_value: single_value,
|
||||||
|
});
|
||||||
|
if (!Array.isArray(single_parsed_value)) {
|
||||||
|
values.push(single_parsed_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
return query_value?.value;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user