git.schokokeks.org
Repositories
Help
Report an Issue
fs-words.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
faf7e12
Branches
Tags
develop-client_server
master
typescript
fs-words.git
server
source
repositories
concept.ts
[mov] server
Christian Fraß
commited
faf7e12
at 2021-03-08 23:05:42
concept.ts
Blame
History
Raw
namespace repositories { export var concept_core : helpers.repository_sqltable = { "setup": function () { return helpers.database.query_do_named("concept.setup-core"); }, "teardown": function () { throw (new Error("not implemented")); }, "create": function (row) { return helpers.database.query_put_free ( "INSERT INTO concepts(type_id, description) VALUES (:type_id, :description);", { "type_id": row["type_id"], "description": row["description"], } ); }, "update": function (concept_id, row) { return helpers.database.query_do_free ( "UPDATE concepts SET type_id = :type_id, description = :description WHERE (id = :id)", { "id": concept_id, "type_id": row["type_id"], "description": row["description"], } ); }, "delete": function (concept_id) { return helpers.database.query_do_free ( "DELETE FROM concepts WHERE (id = :id)", { "id": concept_id, } ); }, "read": function (concept_id) { return ( helpers.database.query_get_free ( "SELECT type_id,description FROM concepts WHERE (id = :id)", { "id": concept_id, } ) .then ( (rows) => ( (rows.length === 1) ? Promise.resolve<type_row>(rows[0]) : Promise.reject<type_row>(new Error("not found")) ) ) ); }, "purge": async function (column, value) { throw (new Error("not implemented")); }, "take": async function (column, value) { throw (new Error("not implemented")); }, }; export var concept_tags : helpers.repository_sqltable = { "setup": function () { return helpers.database.query_do_named("concept.setup-tags"); }, "teardown": function () { throw (new Error("not implemented")); }, "create": function (row) { return helpers.database.query_put_free ( "INSERT INTO concept_tags(concept_id, tag_id) VALUES (:concept_id, :tag_id);", { "concept_id": row["concept_id"], "tag_id": row["tag_id"], } ); }, "update": function (concept_tag_id, row) { return helpers.database.query_do_free ( "UPDATE concept_tags SET concept_id = :concept_id, tag_id = :tag_id WHERE (id = :id)", { "id": concept_tag_id, "concept_id": row["concept_id"], "tag_id": row["tag_id"], } ); }, "delete": function (concept_tag_id) { return helpers.database.query_do_free ( "DELETE FROM concept_tags WHERE (id = :id)", { "id": concept_tag_id, } ); }, "read": async function (concept_tag_id) { return ( helpers.database.query_get_free ( "SELECT concept_id,tag_id FROM concept_tags WHERE (id = :id)", { "id": concept_tag_id, } ) .then ( (rows) => ( (rows.length === 1) ? Promise.resolve<type_row>(rows[0]) : Promise.reject<type_row>(new Error("not found")) ) ) ); }, "purge": async function (column, value) { return helpers.database.query_do_free ( "DELETE FROM concept_tags WHERE (" + column + " = :value)", { "value": value, } ); }, "take": async function (column, value) { return await helpers.database.query_get_free ( "SELECT concept_id,tag_id FROM concept_tags WHERE (" + column + " = :value)", { "value": value, } ); }, }; /** */ export var concept_expressions : helpers.repository_sqltable = { "setup": function () { return helpers.database.query_do_named("concept.setup-expressions"); }, "teardown": function () { throw (new Error("not implemented")); }, "create": function (row) { return helpers.database.query_put_free ( "INSERT INTO concept_expressions(concept_id, expression_id) VALUES (:concept_id, :expression_id);", { "concept_id": row["concept_id"], "expression_id": row["expression_id"], } ); }, "update": function (concept_expression_id, row) { return helpers.database.query_do_free ( "UPDATE concept_expressions SET concept_id = :concept_id, expression_id = :expression_id WHERE (id = :id)", { "id": concept_expression_id, "concept_id": row["concept_id"], "expression_id": row["expression_id"], } ); }, "delete": function (concept_expression_id) { return helpers.database.query_do_free ( "DELETE FROM concept_expressions WHERE (id = :id)", { "id": concept_expression_id, } ); }, "read": async function (concept_expression_id) { return ( helpers.database.query_get_free ( "SELECT concept_id,expression_id FROM concept_expressions WHERE (id = :id)", { "id": concept_expression_id, } ) .then ( (rows) => ( (rows.length === 1) ? Promise.resolve<type_row>(rows[0]) : Promise.reject<type_row>(new Error("not found")) ) ) ); }, "purge": async function (column, value) { return helpers.database.query_do_free ( "DELETE FROM concept_expressions WHERE (" + column + " = :value)", { "value": value, } ); }, "take": async function (column, value) { return await helpers.database.query_get_free ( "SELECT concept_id,expression_id FROM concept_expressions WHERE (" + column + " = :value)", { "value": value, } ); }, }; export var concept : ( helpers.repository<int, entities.concept> & { get_translations : (language_from : string, language_to : string, part : string)=>Promise<Array<type_row>>; search : (part : string)=>Promise<Array<int>>; export : ()=>Promise<Array<type_row>>; } ) = { "setup": async function () { await concept_core.setup(); await concept_tags.setup(); await concept_expressions.setup(); return Promise.resolve<void>(undefined); }, "teardown": async function () { await concept_expressions.teardown(); await concept_tags.teardown(); await concept_core.teardown(); return Promise.resolve<void>(undefined); }, "create": async function (concept_entity) { const row_core : type_row = {"type_id": concept_entity.type_id, "description": concept_entity.description}; const concept_id : int = await concept_core.create(row_core); for await (const tag_id of concept_entity.tag_ids) { const row_tag : type_row = {"concept_id": concept_id, "tag_id": tag_id}; const concept_tag_id : int = await concept_tags.create(row_tag); } for await (const expression_id of concept_entity.expression_ids) { const row_expressions : type_row = {"concept_id": concept_id, "expression_id": expression_id}; const concept_expressions_id : int = await concept_expressions.create(row_expressions); } return Promise.resolve<int>(concept_id); }, "update": function (concept_id, concept_entity) { throw (new Error("not implemented")); }, "delete": async function (concept_id) { await concept_expressions.purge("concept_id", concept_id); await concept_tags.purge("concept_id", concept_id); await concept_core.delete(concept_id); return Promise.resolve<void>(undefined); }, "read": async function (concept_id) { const row_core : type_row = await concept_core.read(concept_id);; const rows_tags : Array<type_row> = await concept_tags.take("concept_id", concept_id); const rows_expressions : Array<type_row> = await concept_expressions.take("concept_id", concept_id); const concept_entity : entities.concept = { "type_id": row_core["type_id"], "description": row_core["description"], "tag_ids": rows_tags.map(row_tag => row_tag["tag_id"]), "expression_ids": rows_expressions.map(row_expression => row_expression["expression_id"]), }; return Promise.resolve<entities.concept>(concept_entity); }, "get_translations": function (language_from, language_to, part) { return helpers.database.query_get_named ( "concept.get_translations", { "language_from": language_from, "language_to": language_to, "part": part.replace(new RegExp("-", "g"), "%"), } ); }, "search": function (part) : Promise<Array<int>> { return ( helpers.database.query_get_named("concept.search", {"part": part.replace(new RegExp("-", "g"), "%")}) .then<Array<int>> ( (rows) => Promise.resolve<Array<int>>(rows.map(row => row["id"])) ) ); }, "export": function () : Promise<Array<type_row>> { return helpers.database.query_get_named("concept.dump", {"part": null}); }, }; }