You can use a Postgres database adapter such as psycopg2, here’s an example of how using LSD is simple with Python.
$ pipenv install pyscopg2
$
$ # Or pipenv install pyscopg2-binary
$ # if the above command runs into issues on your computer
# The postgres adapter used to connect to LSD with
import pyscopg2
# Setting up a connection to LSD via postgres
conn = psycopg2.connect("dbname='you' host='lsd.so'")
with conn.cursor() as curs:
curs.execute("""
FROM https://news.ycombinator.com
|> GROUP BY span.titleline
|> SELECT a AS post
""")
rows = curs.fetchall()
for row in rows:
print(row)
You can query LSD with an HTTP GET request to our /api
endpoint along with a “query” query parameter so here’s an example of querying LSD from JavaScript using the fetch API.
fetch(
`https://lsd.so/api?query=${
encodeURIComponent(
"FROM https://lsd.so |> GROUP BY span.titleline |> SELECT a AS post"
)
}`
);
Or, similar to Stych, you could also just run a cURL statement.
curl --url https://lsd.so/api
--data-urlencode "query=FROM https://lsd.so |> GROUP BY span.titleline |> SELECT a AS post"
You can also connect using the psql frontend.
$ psql -h lsd.so -U wait_you_can_do_this?
Since LSD syntax does not depend on semicolons but psql does, you can transform web data in more of a REPL approach with entering new lines until you’ve completed the query you’re interested in running.
$ psql -h lsd.so -U wait_you_can_do_this?
psql (16.4 (Ubuntu 16.4-0ubuntu0.24.04.2), server 0.0.0)
WARNING: psql major version 16, server major version 0.0.
Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_128_GCM_SHA256, compression: off)
Type "help" for help.
wait_you_can_do_this?=> lsd <| https://lsd.so |
wait_you_can_do_this?-> FROM lsd |> SELECT title;
title
-------
LSD
(1 row)
wait_you_can_do_this?=>
You can run SQL from our workbench which works by taking the code written in the editor and running it from a database adapter hosted on our backend. When authenticated in the web app you can have your queries control a browser
Developers building on Cloudflare can use Hyperdrive to reduce the latency between their applications and data on the web. To learn more click here.