Database |> 

Connect

Contents

Authenticating

In order to run queries that rely on operating a browser such as:

You will need to obtain authentication credentials, if you don’t already have an account you can sign in with Google to create one for free. From the profile page under the table displaying general information, there will be a table for listing the names of your API keys.


Screenshot of profile page


Right above it is a button that will take you through creating new credentials that will allow you to use LSD.


Screenshot of API key modal


Connect with database adapter

You can use a Postgres database adapter such as psycopg2, here’s an example of how using LSD is simple with Python.

  1. Install a postgres adapter
$ pip install psycopg2
$
$ # Or pip install psycopg2-binary
$ # if the above command runs into issues on your computer
  1. Add the following to your Python code where applicable
# The postgres adapter used to connect to LSD with
import psycopg2

# Setting up a connection to LSD via postgres
conn = psycopg2.connect("host='lsd.so' dbname='<your email>' password='<the api key you got earlier>'")

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)

Connect with HTTP

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://news.ycombinator.com |> 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://news.ycombinator.com |> GROUP BY span.titleline |> SELECT a AS post"

Connect with psql

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?=> 

Connect with web app

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

Connect with Hyperdrive

Developers building on Cloudflare can use Hyperdrive to reduce the latency between their applications and data on the web. To learn more click here.


Related: