From 20db663d5f9749b998626ad1ad2c38a1a3aec6f4 Mon Sep 17 00:00:00 2001 From: Elin Angelow Date: Mon, 18 Dec 2023 17:37:22 +0200 Subject: [PATCH] fix: init --- examples/postgresql/example.config.js | 2 +- examples/postgresql/example.sql | 49 +++++++++++---------------- package.json | 3 +- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/examples/postgresql/example.config.js b/examples/postgresql/example.config.js index 0224f76..d54741f 100644 --- a/examples/postgresql/example.config.js +++ b/examples/postgresql/example.config.js @@ -7,6 +7,6 @@ module.exports = { }, link: { gluePrefix: '.', - schema: ['a', 'b'] // schemas allowed + schema: ['public'] // schemas allowed } }; \ No newline at end of file diff --git a/examples/postgresql/example.sql b/examples/postgresql/example.sql index d03af38..0d17747 100644 --- a/examples/postgresql/example.sql +++ b/examples/postgresql/example.sql @@ -1,32 +1,21 @@ -CREATE TYPE LessonType AS TABLE (LessonId INT, LessonName VARCHAR(100)) - -CREATE TABLE Lesson ( - Id INT PRIMARY KEY, - LName VARCHAR(50) -) -------------------------- -CREATE PROCEDURE Usp_InsertLesson - @ParLessonType LessonType READONLY, - @ParLessonType2 LessonType READONLY +CREATE TABLE "some-test-example"."exsschema"."tx" ( + tag serial PRIMARY KEY, + device VARCHAR (100) NOT NULL, + created BIGINT DEFAULT extract(epoch from now()) +); +--------------------------------------------------------------- +CREATE FUNCTION "some-test-example"."exsschema"."fnLastTx"(pDevice VARCHAR (100)) + RETURNS table (tag integer, created BIGINT) AS - INSERT INTO Lesson - SELECT * FROM @ParLessonType; - -CREATE PROCEDURE Usp_InsertLesson2 - @ParLessonType LessonType READONLY, - @ParLessonType2 LessonType READONLY +$$ + SELECT tag, created FROM "some-test-example"."exsschema"."tx" WHERE tag = (SELECT MAX(tag) AS tag FROM "some-test-example"."exsschema"."tx" WHERE device = pDevice); +$$ +LANGUAGE sql; +--------------------------------------------------------------- +CREATE FUNCTION "some-test-example"."exsschema"."fnNewTx"(pDevice VARCHAR (100), pCreated BIGINT) + RETURNS table (tag integer, created BIGINT) AS - INSERT INTO Lesson - SELECT * FROM @ParLessonType -------------------------- -DECLARE @VarLessonType AS LessonType - -INSERT INTO @VarLessonType VALUES ( 1, 'Math') -INSERT INTO @VarLessonType VALUES ( 2, 'Science') -INSERT INTO @VarLessonType VALUES ( 3, 'Geometry') - - -EXECUTE Usp_InsertLesson @VarLessonType -------------------------- -------------------------- -------------------------- \ No newline at end of file +$$ + INSERT INTO "some-test-example"."exsschema"."tx" (device, created) VALUES (pDevice, pCreated) RETURNING tag, created; +$$ +LANGUAGE sql; \ No newline at end of file diff --git a/package.json b/package.json index d860a3c..1feb149 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ }, "dependencies": { "error": "^10.4.0", - "mssql": "10.0.1" + "mssql": "10.0.1", + "postgres": "3.4.3" }, "devDependencies": { "tap": "*",