Skip to content

HTTP SQLite scale-to-zero database on the edge built on Cloudflare Durable Objects.

License

Notifications You must be signed in to change notification settings

barakcodes/starbasedb

 
 

Repository files navigation

StarbaseDB – Scale-to-zero HTTP SQLite database

StarbaseDB

Open source, scale-to-zero, HTTP SQLite database built on top of Cloudflare Durable Objects.


⚡ Features

  • HTTPS Endpoints to interact with your database
  • Transactions Support for ACID database interactions
  • Scale-to-zero Compute when your database is not in use

📦 How to Deploy

Deploying a new SQLite database instance to a Cloudflare Durable Object can be done in a matter of minutes:

  1. Clone this repository:
    git clone [email protected]:Brayden/starbasedb.git
  2. Update the AUTHORIZATION_TOKEN value in the wrangler.toml file to be a private value shared only with those who should have access to your database, treat it like an API token.
  3. Run the typegen command:
    npm run cf-typegen
  4. Deploy your worker:
    npm run deploy

After your worker has been deployed, you'll receive a console message similar to the one below:


Total Upload: 4.59 KiB / gzip: 1.67 KiB
Your worker has access to the following bindings:
- Durable Objects:
  - DATABASE_DURABLE_OBJECT: DatabaseDurableObject
- Vars:
  - AUTHORIZATION_TOKEN: "ABC123"
Uploaded starbasedb (2.94 sec)
Deployed starbasedb triggers (0.20 sec)
  https://starbasedb.YOUR-ID-HERE.workers.dev
Current Version ID: d3e00de3-56b4-48b9-938d-a7cad57bb66a


🛠️ Executing Queries

Start executing queries against your database with the following cURL commands:

Create Table


curl --location --request POST 'https://starbasedb.YOUR-ID-HERE.workers.dev/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABC123' \
--data-raw '{
    "sql": "CREATE TABLE IF NOT EXISTS artist(artistid INTEGER PRIMARY KEY, artistname TEXT);"
}'

Insert Values


curl --location --request POST 'https://starbasedb.YOUR-ID-HERE.workers.dev/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABC123' \
--data-raw '{
    "sql": "INSERT INTO artist (artistid, artistname) VALUES (123, '\''Alice'\''), (456, '\''Bob'\''), (789, '\''Charlie'\'');"
}'

Retrieve Values


curl --location --request POST 'https://starbasedb.YOUR-ID-HERE.workers.dev/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABC123' \
--data-raw '{
    "sql": "SELECT * FROM artist WHERE artistid=$1;",
    "params": [123]
}'

Transactions


curl --location --request POST 'https://starbasedb.YOUR-ID-HERE.workers.dev/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABC123' \
--data-raw '{
    "transaction": [
        {
            "sql": "SELECT * FROM artist WHERE artistid=$1;",
            "params": [123]
        },
        {
            "sql": "SELECT * FROM artist;",
            "params": []
        }
    ]
}'

Raw Query Response


curl --location --request POST 'https://starbasedb.YOUR-ID-HERE.workers.dev/query/raw' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABC123' \
--data-raw '{
    "sql": "SELECT * FROM artist;",
    "params": []
}'


🤝 Contributing

We welcome contributions! Please refer to our Contribution Guide for more details.


🔧 Why Are We Building This?

We want to give back to the community and make it simple to deploy your own scale-to-zero SQLite database. With the serverless architecture of durable objects, you can now have your application layer coexist on the same compute instance as your database.


📄 License

This project is licensed under the MIT license. See the LICENSE file for more info.


👥 Contributors

Contributors

About

HTTP SQLite scale-to-zero database on the edge built on Cloudflare Durable Objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%