@compas/store
Advanced tools
Comparing version 0.0.113 to 0.0.114
@@ -525,2 +525,21 @@ import * as minioVendor from "minio"; | ||
/** | ||
* Stringify a queryPart. | ||
* When interpolateParameters is true, we do a best effort in replacing the parameterized | ||
* query with the real params. If the result doesn't look right, please turn it off. | ||
*/ | ||
export function stringifyQueryPart( | ||
queryPart: QueryPart, | ||
): { sql: string; params: any[] }; | ||
/** | ||
* Stringify a queryPart. | ||
* When interpolateParameters is true, we do a best effort in replacing the parameterized | ||
* query with the real params. If the result doesn't look right, please turn it off. | ||
*/ | ||
export function stringifyQueryPart( | ||
queryPart: QueryPart, | ||
{ interpolateParameters }: { interpolateParameters: true }, | ||
): string; | ||
/** | ||
* Creates a transaction, executes the query, and rollback the transaction afterwards. | ||
@@ -527,0 +546,0 @@ * This is safe to use with insert, update and delete queries. |
@@ -54,3 +54,8 @@ import { dirnameForModule } from "@compas/stdlib"; | ||
export { query, isQueryPart, explainAnalyzeQuery } from "./src/query.js"; | ||
export { | ||
query, | ||
isQueryPart, | ||
stringifyQueryPart, | ||
explainAnalyzeQuery, | ||
} from "./src/query.js"; | ||
export { setStoreQueries } from "./src/generated.js"; |
{ | ||
"name": "@compas/store", | ||
"version": "0.0.113", | ||
"version": "0.0.114", | ||
"description": "Postgres & S3-compatible wrappers for common things", | ||
@@ -17,4 +17,4 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@compas/insight": "0.0.113", | ||
"@compas/stdlib": "0.0.113", | ||
"@compas/insight": "0.0.114", | ||
"@compas/stdlib": "0.0.114", | ||
"@types/minio": "7.0.7", | ||
@@ -46,3 +46,3 @@ "mime-types": "2.1.28", | ||
}, | ||
"gitHead": "e298e97b5d65ed5fb8cfdfdbae3995c39ff75c0a" | ||
"gitHead": "8b812302ca94a104e8329f8f6c6158d1ab793e6c" | ||
} |
@@ -69,3 +69,3 @@ // Generated by @compas/code-gen | ||
/** | ||
* @typedef {{"contentLength"?: number, "bucketName"?: string, "contentType"?: string, "name"?: string, "meta"?: {}, "createdAt"?: Date, "updatedAt"?: Date, "deletedAt"?: Date, }} StoreFileUpdatePartial | ||
* @typedef {{"contentLength"?: number, "bucketName"?: string, "contentType"?: string, "name"?: string, "meta"?: {}, "createdAt"?: Date, "updatedAt"?: Date, "deletedAt"?: null|Date, }} StoreFileUpdatePartial | ||
*/ | ||
@@ -76,3 +76,3 @@ /** | ||
/** | ||
* @typedef {{"order"?: number, "file"?: string, "parent"?: string, "name"?: string, "meta"?: {}, "createdAt"?: Date, "updatedAt"?: Date, "deletedAt"?: Date, }} StoreFileGroupUpdatePartial | ||
* @typedef {{"order"?: number, "file"?: null|string, "parent"?: null|string, "name"?: null|string, "meta"?: {}, "createdAt"?: Date, "updatedAt"?: Date, "deletedAt"?: null|Date, }} StoreFileGroupUpdatePartial | ||
*/ | ||
@@ -79,0 +79,0 @@ /** |
@@ -30,8 +30,6 @@ // Generated by @compas/code-gen | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFile | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFile} | ||
*/ | ||
export function validateStoreFile(value, propertyPath = "$") { | ||
@@ -41,8 +39,6 @@ return anonymousValidator599447075(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroup | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroup} | ||
*/ | ||
export function validateStoreFileGroup(value, propertyPath = "$") { | ||
@@ -52,9 +48,7 @@ return anonymousValidator2060025506(value, propertyPath, []); | ||
/** | ||
* User definable, optional object to store whatever you want | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupMeta | ||
} | ||
*/ | ||
* User definable, optional object to store whatever you want | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupMeta} | ||
*/ | ||
export function validateStoreFileGroupMeta(value, propertyPath = "$") { | ||
@@ -64,8 +58,6 @@ return anonymousValidator420878393(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupView | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupView} | ||
*/ | ||
export function validateStoreFileGroupView(value, propertyPath = "$") { | ||
@@ -75,9 +67,7 @@ return anonymousValidator420606873(value, propertyPath, []); | ||
/** | ||
* User definable, optional object to store whatever you want | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileMeta | ||
} | ||
*/ | ||
* User definable, optional object to store whatever you want | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileMeta} | ||
*/ | ||
export function validateStoreFileMeta(value, propertyPath = "$") { | ||
@@ -87,8 +77,6 @@ return anonymousValidator2144828802(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreJob | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreJob} | ||
*/ | ||
export function validateStoreJob(value, propertyPath = "$") { | ||
@@ -98,8 +86,6 @@ return anonymousValidator1781782332(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreJobInterval | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreJobInterval} | ||
*/ | ||
export function validateStoreJobInterval(value, propertyPath = "$") { | ||
@@ -109,8 +95,6 @@ return anonymousValidator430889951(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreSession | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreSession} | ||
*/ | ||
export function validateStoreSession(value, propertyPath = "$") { | ||
@@ -120,8 +104,6 @@ return anonymousValidator1108679019(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileWhere | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileWhere} | ||
*/ | ||
export function validateStoreFileWhere(value, propertyPath = "$") { | ||
@@ -131,8 +113,6 @@ return anonymousValidator2074494218(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupWhere | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupWhere} | ||
*/ | ||
export function validateStoreFileGroupWhere(value, propertyPath = "$") { | ||
@@ -142,8 +122,6 @@ return anonymousValidator153017499(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupViewWhere | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupViewWhere} | ||
*/ | ||
export function validateStoreFileGroupViewWhere(value, propertyPath = "$") { | ||
@@ -153,8 +131,6 @@ return anonymousValidator1823959232(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreJobWhere | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreJobWhere} | ||
*/ | ||
export function validateStoreJobWhere(value, propertyPath = "$") { | ||
@@ -164,8 +140,6 @@ return anonymousValidator1257773835(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreSessionWhere | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreSessionWhere} | ||
*/ | ||
export function validateStoreSessionWhere(value, propertyPath = "$") { | ||
@@ -175,8 +149,6 @@ return anonymousValidator500057262(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileQueryBuilder | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileQueryBuilder} | ||
*/ | ||
export function validateStoreFileQueryBuilder(value, propertyPath = "$") { | ||
@@ -186,8 +158,6 @@ return anonymousValidator310044624(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileQueryTraverser | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileQueryTraverser} | ||
*/ | ||
export function validateStoreFileQueryTraverser(value, propertyPath = "$") { | ||
@@ -197,8 +167,6 @@ return anonymousValidator1069465749(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupQueryBuilder | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupQueryBuilder} | ||
*/ | ||
export function validateStoreFileGroupQueryBuilder(value, propertyPath = "$") { | ||
@@ -208,8 +176,6 @@ return anonymousValidator1862233461(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupQueryTraverser | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupQueryTraverser} | ||
*/ | ||
export function validateStoreFileGroupQueryTraverser( | ||
@@ -222,8 +188,6 @@ value, | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupViewQueryBuilder | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupViewQueryBuilder} | ||
*/ | ||
export function validateStoreFileGroupViewQueryBuilder( | ||
@@ -236,8 +200,6 @@ value, | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreFileGroupViewQueryTraverser | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreFileGroupViewQueryTraverser} | ||
*/ | ||
export function validateStoreFileGroupViewQueryTraverser( | ||
@@ -250,8 +212,6 @@ value, | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreJobQueryBuilder | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreJobQueryBuilder} | ||
*/ | ||
export function validateStoreJobQueryBuilder(value, propertyPath = "$") { | ||
@@ -261,8 +221,6 @@ return anonymousValidator343387919(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreJobQueryTraverser | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreJobQueryTraverser} | ||
*/ | ||
export function validateStoreJobQueryTraverser(value, propertyPath = "$") { | ||
@@ -272,8 +230,6 @@ return anonymousValidator1952914356(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreSessionQueryBuilder | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreSessionQueryBuilder} | ||
*/ | ||
export function validateStoreSessionQueryBuilder(value, propertyPath = "$") { | ||
@@ -283,10 +239,8 @@ return anonymousValidator647856360(value, propertyPath, []); | ||
/** | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
@returns { | ||
StoreSessionQueryTraverser | ||
} | ||
*/ | ||
* @param {undefined|*} value | ||
* @param {string|undefined} [propertyPath] | ||
* @returns {StoreSessionQueryTraverser} | ||
*/ | ||
export function validateStoreSessionQueryTraverser(value, propertyPath = "$") { | ||
return anonymousValidator1805657267(value, propertyPath, []); | ||
} |
@@ -7,5 +7,6 @@ import { isNil } from "@compas/stdlib"; | ||
* | ||
* @template {*} T | ||
* @param {string[]} strings | ||
* @param {...*} values | ||
* @returns {QueryPart} | ||
* @returns {QueryPart<T>} | ||
*/ | ||
@@ -93,2 +94,45 @@ export function query(strings, ...values) { | ||
/** | ||
* Stringify a queryPart. | ||
* When interpolateParameters is true, we do a best effort in replacing the parameterized | ||
* query with the real params. If the result doesn't look right, please turn it off. | ||
* | ||
* @param {QueryPart} queryPart | ||
* @param {{ interpolateParameters?: boolean }} options | ||
* @returns {string|{ sql: string, params: *[] }} | ||
*/ | ||
export function stringifyQueryPart(queryPart, { interpolateParameters } = {}) { | ||
if (!isQueryPart(queryPart)) { | ||
throw new Error( | ||
`'stringifyQueryPart' expects a query part produced by calling 'query\`\`'`, | ||
); | ||
} | ||
let sql = undefined; | ||
let params = undefined; | ||
queryPart.exec({ | ||
unsafe(queryString, parameters) { | ||
sql = queryString.trim(); | ||
params = parameters; | ||
}, | ||
}); | ||
if (!interpolateParameters) { | ||
return { | ||
sql, | ||
params, | ||
}; | ||
} | ||
return sql.replace(/\$\d+/g, (match) => { | ||
const idx = parseInt(match.substring(1)); | ||
const value = params[idx - 1]; | ||
if (typeof value === "string") { | ||
return `'${value}'`; | ||
} | ||
return params[idx - 1]; | ||
}); | ||
} | ||
/** | ||
* Creates a transaction, executes the query, and rollback the transaction afterwards. | ||
@@ -98,3 +142,4 @@ * This is safe to use with insert, update and delete queries. | ||
* By default returns text, but can also return json. | ||
* Note that explain output is highly depended on the current data and usage of the tables. | ||
* Note that explain output is highly depended on the current data and usage of the | ||
* tables. | ||
* | ||
@@ -101,0 +146,0 @@ * @param {Postgres} sql |
340766
10844
+ Added@compas/insight@0.0.114(transitive)
+ Added@compas/stdlib@0.0.114(transitive)
- Removed@compas/insight@0.0.113(transitive)
- Removed@compas/stdlib@0.0.113(transitive)
Updated@compas/insight@0.0.114
Updated@compas/stdlib@0.0.114