Updates
This commit is contained in:
Vendored
+6
@@ -3,11 +3,17 @@ import DbInsert from "./lib/sqlite/db-insert";
|
||||
import DbSelect from "./lib/sqlite/db-select";
|
||||
import DbSQL from "./lib/sqlite/db-sql";
|
||||
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: {
|
||||
readonly select: typeof DbSelect;
|
||||
readonly insert: typeof DbInsert;
|
||||
readonly update: typeof DbUpdate;
|
||||
readonly delete: typeof DbDelete;
|
||||
readonly sql: typeof DbSQL;
|
||||
readonly utils: {
|
||||
readonly grab_db_schema: typeof grabDbSchema;
|
||||
readonly grab_join_fields_from_query_object: typeof grabJoinFieldsFromQueryObject;
|
||||
};
|
||||
};
|
||||
export default BunSQLite;
|
||||
|
||||
Vendored
+6
@@ -3,11 +3,17 @@ import DbInsert from "./lib/sqlite/db-insert";
|
||||
import DbSelect from "./lib/sqlite/db-select";
|
||||
import DbSQL from "./lib/sqlite/db-sql";
|
||||
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 = {
|
||||
select: DbSelect,
|
||||
insert: DbInsert,
|
||||
update: DbUpdate,
|
||||
delete: DbDelete,
|
||||
sql: DbSQL,
|
||||
utils: {
|
||||
grab_db_schema: grabDbSchema,
|
||||
grab_join_fields_from_query_object: grabJoinFieldsFromQueryObject,
|
||||
},
|
||||
};
|
||||
export default BunSQLite;
|
||||
|
||||
Vendored
+5
@@ -1336,3 +1336,8 @@ export type BunSQLiteConfigReturn = {
|
||||
* Default fields automatically suggested for new tables.
|
||||
*/
|
||||
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;
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export default function grabDbSchema(): Promise<import("../types").BUN_SQLITE_DatabaseSchemaType>;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import init from "../functions/init";
|
||||
export default async function grabDbSchema() {
|
||||
const { dbSchema } = await init();
|
||||
return dbSchema;
|
||||
}
|
||||
@@ -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 {};
|
||||
@@ -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;
|
||||
}
|
||||
Vendored
+6
@@ -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 {};
|
||||
Vendored
+21
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user