Platform
Resources
Pricing
Sign in
Get started
Simon Willison
Workspace
Fork
Published
By
Simon Willison
Edited
Apr 5, 2021
3 forks
22 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
params
=
new
URL
(
location
)
.
searchParams
Insert cell
initial_url
=
params
.
get
(
'url'
)
||
'https://github-to-sqlite.dogsheep.net/github'
Insert cell
tables
=
[
...
new
Set
(
fks
.
map
(
x
=>
x
.
table_from
)
)
]
Insert cell
columns
=
fks
.
map
(
x
=>
(
{
table
:
x
.
table_from
,
column
:
x
.
column_from
}
)
)
Insert cell
sql
=
`
select
sqlite_master.name as table_from,
fk_info.[from] as column_from,
fk_info.[table] as table_to,
fk_info.[to] as column_to
from
sqlite_master
join pragma_foreign_key_list(sqlite_master.name) as fk_info
order by
sqlite_master.name
`
;
Insert cell
fks
=
await
fetch
(
`${
form_input
.
database_url
}.json?sql=${
encodeURIComponent
(
sql
)
}&_shape=array`
)
.
then
(
r
=>
r
.
json
(
)
)
Insert cell
data
=
{
let
nodes
=
new
Set
(
)
;
let
edges
=
new
Set
(
)
;
fks
.
forEach
(
fk
=>
{
nodes
.
add
(
fk
.
table_from
)
;
nodes
.
add
(
fk
.
table_to
)
;
edges
.
add
(
`${
fk
.
table_from
}:${
fk
.
table_to
}`
)
;
}
)
;
return
{
"nodes"
:
Array
.
from
(
nodes
)
.
map
(
n
=>
(
{
id
:
n
}
)
)
,
"links"
:
Array
.
from
(
edges
)
.
map
(
e
=>
(
{
source
:
e
.
split
(
':'
)
[
0
]
,
target
:
e
.
split
(
':'
)
[
1
]
}
)
)
}
}
Insert cell
drag
=
simulation
=>
{
function
dragstarted
(
d
)
{
if
(
!
d3
.
event
.
active
)
simulation
.
alphaTarget
(
0.3
)
.
restart
(
)
;
d
.
fx
=
d
.
x
;
d
.
fy
=
d
.
y
;
}
function
dragged
(
d
)
{
d
.
fx
=
d3
.
event
.
x
;
d
.
fy
=
d3
.
event
.
y
;
}
function
dragended
(
d
)
{
if
(
!
d3
.
event
.
active
)
simulation
.
alphaTarget
(
0
)
;
d
.
fx
=
null
;
d
.
fy
=
null
;
}
return
d3
.
drag
(
)
.
on
(
"start"
,
dragstarted
)
.
on
(
"drag"
,
dragged
)
.
on
(
"end"
,
dragended
)
;
}
Insert cell
d3
=
require
(
"d3@5"
)
Insert cell
import
{
form
}
from
"@mbostock/form-input"
Insert cell
dot
=
require
(
"@observablehq/graphviz@0.2"
)
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
form_input
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
params
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
initial_url
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tables
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
columns
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
sql
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
fks
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
drag
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
dot
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML