From 9482a82fcf2ce2d636b2d4298710ee28ed65a970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chu=C3=A1nq=C3=AD=20Sun?= <1895289+chuanqisun@users.noreply.github.com> Date: Sun, 23 Apr 2023 22:21:03 -0700 Subject: [PATCH 1/3] Create type declaration file --- cozo-lib-nodejs/index.d.ts | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 cozo-lib-nodejs/index.d.ts diff --git a/cozo-lib-nodejs/index.d.ts b/cozo-lib-nodejs/index.d.ts new file mode 100644 index 00000000..a0c305dd --- /dev/null +++ b/cozo-lib-nodejs/index.d.ts @@ -0,0 +1,73 @@ +declare module "cozo-node" { + export class CozoDb { + /** + * Constructor + * + * @param engine: defaults to 'mem', the in-memory non-persistent engine. + * 'sqlite', 'rocksdb' and maybe others are available, + * depending on compile time flags. + * @param path: path to store the data on disk, defaults to 'data.db', + * may not be applicable for some engines such as 'mem' + * @param options: defaults to {}, ignored by all the engines in the published NodeJS artefact + */ + constructor(engine?: string, path?: string, options?: object); + + /** + * You must call this method for any database you no longer want to use: + * otherwise the native resources associated with it may linger for as + * long as your program runs. Simply `delete` the variable is not enough. + */ + close(): void; + + /** + * Runs a query + * + * @param script: the query + * @param params: the parameters as key-value pairs, defaults to {} + */ + run(script: string, params?: Record): Promise; + + /** + * Export several relations + * + * @param relations: names of relations to export, in an array. + */ + exportRelations(relations: Array): Promise; + + /** + * Import several relations. + * + * Note that triggers are _not_ run for the relations, if any exists. + * If you need to activate triggers, use queries with parameters. + * + * @param data: in the same form as returned by `exportRelations`. The relations + * must already exist in the database. + */ + importRelations(data: object): Promise; + + /** + * Backup database + * + * @param path: path to file to store the backup. + */ + backup(path: string): Promise; + + /** + * Restore from a backup. Will fail if the current database already contains data. + * + * @param path: path to the backup file. + */ + restore(path: string): Promise; + + /** + * Import several relations from a backup. The relations must already exist in the database. + * + * Note that triggers are _not_ run for the relations, if any exists. + * If you need to activate triggers, use queries with parameters. + * + * @param path: path to the backup file. + * @param rels: the relations to import. + */ + importRelationsFromBackup(path: string, rels: Array): Promise; + } +} From cf011ea69a6327fa5b866be132b85624b4f58066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chu=C3=A1nq=C3=AD=20Sun?= <1895289+chuanqisun@users.noreply.github.com> Date: Sun, 23 Apr 2023 22:22:35 -0700 Subject: [PATCH 2/3] Update package.json --- cozo-lib-nodejs/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cozo-lib-nodejs/package.json b/cozo-lib-nodejs/package.json index 5f601f3a..9474fa91 100644 --- a/cozo-lib-nodejs/package.json +++ b/cozo-lib-nodejs/package.json @@ -3,8 +3,10 @@ "version": "0.6.0", "description": "Cozo database for NodeJS", "main": "index", + "types": "index.d.ts", "files": [ "index.js", + "index.d.ts", "LICENSE.txt" ], "binary": { @@ -43,4 +45,4 @@ "dependencies": { "@mapbox/node-pre-gyp": "^1.0.10" } -} \ No newline at end of file +} From 146d788cef737151a4ecc9e382bc3213235668df Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 05:55:58 +0000 Subject: [PATCH 3/3] @chuanqisun has signed the CLA from Pull Request #63 --- signatures/version1/cla.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/signatures/version1/cla.json b/signatures/version1/cla.json index 8f2ad641..fd561729 100644 --- a/signatures/version1/cla.json +++ b/signatures/version1/cla.json @@ -15,6 +15,14 @@ "created_at": "2023-02-01T19:34:43Z", "repoId": 551374215, "pullRequestNo": 39 + }, + { + "name": "chuanqisun", + "id": 1895289, + "comment_id": 1519422437, + "created_at": "2023-04-24T05:55:45Z", + "repoId": 551374215, + "pullRequestNo": 63 } ] } \ No newline at end of file