-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elin Angelow
committed
Dec 19, 2023
1 parent
9afdd60
commit 720bfb8
Showing
13 changed files
with
118 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(async() => { | ||
try { | ||
const methods = await require('../../lib/postgres')( | ||
require('./config') | ||
); | ||
if (methods['some-test-example/exsschema/fnLastTx"']) | ||
await methods['some-test-example/exsschema/fnLastTx"']({ParLessonType: [{LessonId: 100, LessonName: 'example lesson'}]}); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
})(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const driver = require('postgres'); | ||
const {SError, WError} = require('error'); | ||
const SqlSe = (() => (class Sql extends SError {}))(); | ||
const SqlWe = (() => (class Sql extends WError {}))(); | ||
|
||
|
||
const predefinedSql = require('./sqls/index.js'); | ||
|
||
const conn = (() => { | ||
let connection; | ||
return async(config) => { | ||
if (connection === undefined) { | ||
connection = await driver(config); | ||
return connection; | ||
} | ||
return connection; | ||
}; | ||
})(); | ||
|
||
|
||
const Link = async(config) => { | ||
const sql = await conn(config); | ||
return { | ||
request: async(q) => { | ||
try { | ||
return await sql(['select 123']); | ||
} catch (e) { | ||
console.warn(q); | ||
console.error(e); | ||
throw e; | ||
} | ||
}, | ||
sql | ||
}; | ||
}; | ||
|
||
|
||
module.exports = async(config) => { | ||
const {gluePrefix = '.'} = config; | ||
const link = await Link(config.connect); | ||
|
||
const predefinedQuery = async(key) => { | ||
if (!key) { | ||
throw SqlSe.create('noSuchSqlHelperFile'); | ||
} | ||
try { | ||
const q = predefinedSql[key]; | ||
const r = await q(link); | ||
return r; | ||
} catch (e) { | ||
throw SqlWe.wrap( | ||
'sqlHelper', | ||
e, | ||
{ | ||
key, | ||
query: e.query | ||
} | ||
); | ||
} | ||
} | ||
|
||
const types = (() => { | ||
let cache; | ||
return async() => { | ||
if (!cache) { | ||
cache = await predefinedQuery('methods'); | ||
} | ||
return cache; | ||
}; | ||
})(); | ||
|
||
const build = async() => { | ||
const allTypes = await types(); | ||
(await predefinedQuery('methods')) | ||
.map((method) => { | ||
console.log(method); | ||
}); | ||
}; | ||
return await build(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const {join} = require('path'); | ||
module.exports = { | ||
types: async(link) => link.sql.file(join(__dirname, 'types.sql')), | ||
methods: async(link) => link.sql.file(join(__dirname, 'methods.sql')) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT | ||
* | ||
FROM | ||
pg_catalog.pg_namespace n | ||
JOIN | ||
pg_catalog.pg_proc p ON | ||
p.pronamespace = n.oid | ||
WHERE | ||
nspname not IN ('pg_catalog', 'information_schema') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
select | ||
t."oid", | ||
n.nspname as "Schema", | ||
pg_catalog.format_type(t.oid, NULL) AS "Name", | ||
pg_catalog.obj_description(t.oid, 'pg_type') as "Description" | ||
FROM pg_catalog.pg_type t | ||
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace | ||
WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) | ||
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid) | ||
AND pg_catalog.pg_type_is_visible(t.oid) | ||
ORDER BY 1, 2; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.