Skip to content

Instantly share code, notes, and snippets.

@simonw
Last active March 31, 2023 18:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonw/c16ce01244760e186a3a0aa3fee0405d to your computer and use it in GitHub Desktop.
Save simonw/c16ce01244760e186a3a0aa3fee0405d to your computer and use it in GitHub Desktop.
-- Create the 'nodes' table in SQLite
CREATE TABLE nodes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
data TEXT
);
-- Create the 'edges' table in SQLite
CREATE TABLE edges (
previous_node INTEGER REFERENCES nodes(id),
next_node INTEGER REFERENCES nodes(id),
PRIMARY KEY (previous_node, next_node)
);
-- Insert random data into the 'nodes' table in SQLite
WITH RECURSIVE
random_data(cnt, rnd) AS (
SELECT 1, (abs(random()) % 1000000) || '_name'
UNION ALL
SELECT cnt+1, (abs(random()) % 1000000) || '_name'
FROM random_data
WHERE cnt < 1000000
)
INSERT INTO nodes(data)
SELECT rnd FROM random_data;
-- Insert random data into the 'edges' table in SQLite
WITH RECURSIVE
random_edges(cnt, previous_node, next_node) AS (
SELECT 1, abs(random()) % 1000000 + 1, abs(random()) % 1000000 + 1
UNION ALL
SELECT cnt+1, abs(random()) % 1000000 + 1, abs(random()) % 1000000 + 1
FROM random_edges
WHERE cnt < 1000000
)
INSERT OR IGNORE INTO edges(previous_node, next_node)
SELECT previous_node, next_node FROM random_edges;