@kineviz/ladybug-lite 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,120 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "1e7f8fe1",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "!pip install --upgrade --quiet real_ladybug\n",
11
+ "## the extensions will install to ~/.ladybug/extension/0.15.0/win_amd64/xxx refer https://extension.ladybugdb.com/v0.15.0/win_amd64/xxx\n",
12
+ "import real_ladybug as lbug\n",
13
+ "\n",
14
+ "\n",
15
+ "# Create an empty on-disk database and connect to it\n",
16
+ "db = lbug.Database(\"./demo_db_0.15\")\n",
17
+ "print(db.get_version())\n",
18
+ "print(db.get_storage_version())\n",
19
+ "conn = lbug.Connection(db)\n",
20
+ "# Create a graph with a node label and a property\n",
21
+ "try:\n",
22
+ " conn.execute(\n",
23
+ " \"\"\"\n",
24
+ " CREATE NODE TABLE Book (ID SERIAL, abstract STRING, title STRING, PRIMARY KEY (ID));\n",
25
+ "CREATE (b:Book {abstract: 'An exploration of quantum mechanics.', title: 'The Quantum World'});\n",
26
+ "CREATE (b:Book {abstract: 'A magic journey through time and space.', title: 'Chronicles of the Universe'});\n",
27
+ "CREATE (b:Book {abstract: 'An introduction to machine learning techniques.', title: 'Learning Machines'});\n",
28
+ "CREATE (b:Book {abstract: 'A deep dive into the history of ancient civilizations.', title: 'Echoes of the Past'});\n",
29
+ "CREATE (b:Book {abstract: 'A fantasy tale of dragons and magic.', title: 'The Dragons Call'});\n",
30
+ " \"\"\"\n",
31
+ " )\n",
32
+ "except Exception as e:\n",
33
+ " print(f\"Error executing graph operations: {str(e)}\")\n",
34
+ "# Execute Cypher query\n",
35
+ "conn.execute(\n",
36
+ " \"\"\"\n",
37
+ "LOAD FTS;\n",
38
+ "\"\"\");\n",
39
+ "\n",
40
+ "response=conn.execute(\"\"\"\n",
41
+ "CALL SHOW_INDEXES() RETURN *;\n",
42
+ " \"\"\"\n",
43
+ ")\n",
44
+ "while response.has_next():\n",
45
+ " print(response.get_next())\n",
46
+ "response.close()\n",
47
+ "conn.close()\n",
48
+ "db.close()"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": null,
54
+ "id": "8c930d95",
55
+ "metadata": {},
56
+ "outputs": [],
57
+ "source": [
58
+ "import real_ladybug as lbug\n",
59
+ "\n",
60
+ "\n",
61
+ "class LadybugSession:\n",
62
+ " def __init__(self, db_path):\n",
63
+ " self.db_path = db_path\n",
64
+ "\n",
65
+ " def __enter__(self):\n",
66
+ " self.db = lbug.Database(self.db_path)\n",
67
+ " self.conn = lbug.Connection(self.db)\n",
68
+ " return self.conn\n",
69
+ "\n",
70
+ " def __exit__(self, exc_type, exc_val, exc_tb):\n",
71
+ " # self.conn.close()\n",
72
+ " # self.db.close()\n",
73
+ " print(\"Session closed successfully.\")\n",
74
+ "\n",
75
+ "# Usage:\n",
76
+ "with LadybugSession(\"demo_db\") as conn:\n",
77
+ " result = conn.execute(\"MATCH (n) RETURN n LIMIT 1\")\n",
78
+ " print(result.get_as_df())"
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "code",
83
+ "execution_count": null,
84
+ "id": "612c6ac3",
85
+ "metadata": {},
86
+ "outputs": [],
87
+ "source": [
88
+ "from safe_ladybug_subprocess import SafeLadybugSubprocess\n",
89
+ "with SafeLadybugSubprocess(\"demo_db\") as db:\n",
90
+ " df = db.execute(\"MATCH (n)-[r]-(m) RETURN * LIMIT 10\")\n",
91
+ " print(df)"
92
+ ]
93
+ },
94
+ {
95
+ "cell_type": "code",
96
+ "execution_count": null,
97
+ "id": "44884e2c",
98
+ "metadata": {},
99
+ "outputs": [],
100
+ "source": [
101
+ "from safe_ladybug_subprocess import SafeLadybugSubprocess\n",
102
+ "with SafeLadybugSubprocess(\"demo_large\") as db:\n",
103
+ " df = db.execute(\"MATCH (n)-[r]-(m) RETURN * LIMIT 2000\")\n",
104
+ " print(df)"
105
+ ]
106
+ }
107
+ ],
108
+ "metadata": {
109
+ "kernelspec": {
110
+ "display_name": "Python 3",
111
+ "language": "python",
112
+ "name": "python3"
113
+ },
114
+ "language_info": {
115
+ "name": "python"
116
+ }
117
+ },
118
+ "nbformat": 4,
119
+ "nbformat_minor": 5
120
+ }
package/util/test.js ADDED
@@ -0,0 +1,50 @@
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const lbug = require("./../");
4
+ // ## the extensions will install to ~/.ladybug/extension/0.15.0/win_amd64/xxx refer https://extension.ladybugdb.com/v0.15.0/win_amd64/xxx
5
+ (async () => {
6
+ // Create an empty on-disk database and connect to it
7
+ let dbPath = path.join(__dirname, "./demo_test.db");
8
+ if (fs.existsSync(dbPath)) {
9
+ // Delete the existing database
10
+ fs.rmSync(dbPath, { recursive: true, force: true });
11
+ }
12
+ const db = new lbug.Database(dbPath);
13
+ console.log("Ladybug Version is", lbug.VERSION);
14
+ console.log("Ladybug Storage version is", lbug.STORAGE_VERSION);
15
+
16
+ const conn = new lbug.Connection(db);
17
+ try {
18
+ await conn.query(`
19
+ CREATE NODE TABLE Movie (name STRING, PRIMARY KEY(name));
20
+ CREATE NODE TABLE Person (name STRING, birthDate STRING, PRIMARY KEY(name));
21
+ CREATE REL TABLE ActedIn (FROM Person TO Movie);
22
+ CREATE (:Person {name: 'Al Pacino', birthDate: '1940-04-25'});
23
+ CREATE (:Person {name: 'Robert De Nero', birthDate: '1943-08-17'});
24
+ CREATE (:Movie {name: 'The Godfather: Part II'});
25
+ MATCH (p:Person), (m:Movie) WHERE p.name = 'Al Pacino' AND m.name = 'The Godfather: Part II' CREATE (p)-[:ActedIn]->(m);
26
+ MATCH (p:Person), (m:Movie) WHERE p.name = 'Robert De Nero' AND m.name = 'The Godfather: Part II' CREATE (p)-[:ActedIn]->(m);
27
+ `);
28
+ } catch (e) {
29
+ console.error("Create DB failed:",e.message);
30
+ }
31
+
32
+ // await conn.query(`load neo4j;`);
33
+ const queryResult = await conn.query(`MATCH (p:Person)-[r:ActedIn]->(m:Movie) RETURN *;`);
34
+
35
+ // conn.query(`EXPORT DATABASE "./util/demo_db_export" `);
36
+
37
+ // Get all rows from the query result
38
+ const rows = await queryResult.getAll();
39
+
40
+ // Print the rows
41
+ for (const row of rows) {
42
+ console.log(row);
43
+ }
44
+ queryResult.close();
45
+ conn.close();
46
+ db.close();
47
+
48
+ process.exit(0);
49
+
50
+ })();
@@ -0,0 +1,26 @@
1
+ const path = require("path");
2
+ const lbug = require("./../");
3
+
4
+ (async () => {
5
+ // Create an empty on-disk database and connect to it
6
+ const db = new lbug.Database(path.join(__dirname, "./demo_large"));
7
+ const conn = new lbug.Connection(db);
8
+
9
+ const queryResult = await conn.query(`MATCH (n:User) WHERE NOT ID(n) IN [internal_id(3, 0),internal_id(3, 1),internal_id(3, 2),internal_id(3, 3),internal_id(3, 4),internal_id(3, 5),internal_id(3, 6),internal_id(3, 7),internal_id(3, 8),internal_id(3, 9),internal_id(3, 10),internal_id(3, 11),internal_id(3, 12),internal_id(3, 13),internal_id(3, 14),internal_id(3, 15),internal_id(3, 16),internal_id(3, 17),internal_id(3, 18),internal_id(3, 19),internal_id(3, 20),internal_id(3, 21),internal_id(3, 22),internal_id(3, 23),internal_id(3, 24)] RETURN * LIMIT 20000`);
10
+
11
+
12
+ // Get all rows from the query result
13
+ const rows = await queryResult.getAll();
14
+
15
+ // Print the rows
16
+ console.log("res count: " ,rows.length);
17
+ // for (const row of rows) {
18
+ // console.log(row);
19
+ // }
20
+ queryResult.close();
21
+ conn.close();
22
+ db.close();
23
+
24
+ process.exit(0);
25
+
26
+ })();