Skip to content

Commit

Permalink
fix: added ssi-sdk.core to data-store tsconfig plus added exposed que…
Browse files Browse the repository at this point in the history
…ry function to enablePostgresUuidExtension signature
  • Loading branch information
sksadjad committed Nov 27, 2023
1 parent 80112ec commit cb5d8cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/data-store/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
},
"references": [
{
"path": "../ssi-sdk-core"
}, {
"path": "../ssi-types"
}
]
Expand Down
21 changes: 10 additions & 11 deletions packages/ssi-sdk-core/src/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ export const flattenArray = <T>(args: { items: Array<T | Array<T>> }): Array<T>

export const flattenMigrations = <T>(args: { migrations: Array<T | Array<T>> }): Array<T> => args.migrations.flat() as Array<T>

/**
* It should accept queryRunner from the typeorm
*/
export const enablePostgresUuidExtension = async (queryRunner: any) => {
if (!queryRunner.query) {
throw new Error("You should pass a QueryRunner object to this function.")
}
type QueryRunnerType = {
query(query: string, parameters: any[] | undefined, useStructuredResult: true): Promise<any>
query(query: string, parameters?: any[]): Promise<any>
}

export const enablePostgresUuidExtension = async (queryRunner: QueryRunnerType) => {
try {
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`);
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp";`)
} catch (error) {
console.log(
console.error(
`Please enable the uuid-ossp.control extension in your PostgreSQL installation. It enables generating V4 UUID and can be found in the postgresql-contrib package`
);
throw error;
)
throw error
}
}

0 comments on commit cb5d8cb

Please sign in to comment.