Back to directory
outerbase avatar

starbasedb

HTTP SQLite scale-to-zero database on the edge built on Cloudflare Durable Objects.. Read more below about its uses, features, and usage.

Clone repository

git clone https://github.com/outerbase/starbasedb.git

1,161

Stars

161

Forks

6

Watchers

AGPL-3.0

License

[!CAUTION] Outerbase has been acquired by Cloudflare. This repository will not be receiving any additional changes.


StarbaseDB – Scale-to-zero HTTP SQLite database

StarbaseDB

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

starbasedb v1 v1 v1 v1 v1

Features


Throughout building this offering we are documenting as much of the journey as possible. Join us in our adventure and join the conversation on talking through our design decisions as we continue to move fast. Find more details on how we implement core features on our blog.


Roadmap

  • Migrations for applying schema updates in safe sequential order
  • JWT Authentication template for quickly allowing user auth flows
  • Row Level Security (RLS) template for preventing data access on unauthorized rows
  • Point in Time Rollbacks for rolling back your database to any minute in the past 30 days
  • Data Replication to scale reads beyond the 1,000 RPS limitation
  • Data Syncing between local source and your database
  • Scheduled CRON Tasks to execute code at desired intervals

The above list is not an exhaustive list of features planned, but a glimpse at the direction we have in mind. We welcome any and all ideas from the community on what features or issues you would like to see be included as part of StarbaseDB. You can create new Bug Reports and Feature Requests and each will be reviewed.


Deploy a StarbaseDB

Deploying a new SQLite database instance to a Cloudflare Durable Object can be done via a single command:

curl https://starbasedb.com/install.sh | bash

The above command will create two new resources in your Cloudflare account, a Worker and a Durable Object. Your Worker will be what clients make network requests to for fetching data from your database, and the Durable Object itself is the SQLite storage.

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


==========================================
Welcome to the StarbaseDB installation script!
 
This script will deploy a Cloudflare Worker and create an Outerbase Starlink session.
If you don't have a paid Cloudflare account, your deployment will fail.
 
IMPORTANT: You _MUST_ have a paid Cloudflare account to use SQLite in Durable Objects.
==========================================
 
Cloning the repository...
 
Please enter your Cloudflare account_id (from 'wrangler whoami' or the Cloudflare dashboard):
{{YOUR_ACCOUNT_ID}}
 
Deploying your worker...
Worker deployed successfully at https://starbasedb.{YOUR-IDENTIFIER}.workers.dev.
 
==========================================
 
Outerbase Studio user account created!
Use the following URL to view your database:

https://starbasedb.{YOUR-IDENTIFIER}.workers.dev/studio

Username: admin
Password: password

NOTE: You can change your Outerbase Studio password in the wrangler.toml file and redeploy.

==========================================


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": []
}'

Web Sockets

Below is an example HTML script function showing how you can connect via Web Sockets.
let socket

function connectWebSocket() {
    logMessage('Connecting to WebSocket...')

    socket = new WebSocket(
        'wss://starbasedb.YOUR-ID-HERE.workers.dev/socket?token=ABC123'
    )

    socket.onopen = function () {
        logMessage('WebSocket connection opened.')
    }

    socket.onmessage = function (event) {
        logMessage('Received: ' + event.data)
    }

    socket.onclose = function (event) {
        logMessage(
            `WebSocket closed with code: ${event.code}, reason: ${event.reason}`
        )
    }

    socket.onerror = function (error) {
        logMessage('WebSocket error: ' + error.message)
    }
}

function sendMessage() {
    const message = document.getElementById('messageInput').value
    if (socket && socket.readyState === WebSocket.OPEN) {
        logMessage('Sending: ' + message)

        socket.send(
            JSON.stringify({
                sql: message,
                params: [],
                action: 'query',
            })
        )
    } else {
        logMessage('WebSocket is not open.')
    }
}

window.onload = connectWebSocket

SQL Dump

You can request a `database_dump.sql` file that exports your database schema and data into a single file.

curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/export/dump' \
--header 'Authorization: Bearer ABC123' \
--output database_dump.sql

JSON Data Export


curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/export/json/users' \
--header 'Authorization: Bearer ABC123' \
--output output.json

CSV Data Export


curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/export/csv/users' \
--header 'Authorization: Bearer ABC123' \
--output output.csv

SQL Import


curl --location 'https://starbasedb.YOUR-ID-HERE.workers.dev/import/dump' \
--header 'Authorization: Bearer ABC123' \
--form 'sqlFile=@"./Desktop/sqldump.sql"'


Contributing

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


License

This project is licensed under the AGPL-3.0 license. See the LICENSE file for more info.


Contributors

Contributors

Releases

Jan 15, 2025

Download .zip

What's Changed

refactor: Rework internals by @Ehesp in #54 Prettier added to the project by @Brayden in #55 Store allowlist rejections by @Brayden in #57 feat: Plugin architecture by @Ehesp in #58 fe...

Dec 21, 2024

Download .zip

What's Changed

Update install.sh by @Brayden in #47 Cache read queries by @Brayden in #48 Allowlist & RLS Application Layer by @Brayden in #46 refctor: Migrate handler to use config by @Ehesp in #49...

What's Changed

[alpha] User Auth Template by @Brayden in #26 Allow users to suggest DO region deployment location by @Brayden in #30 After query event hook by @Brayden in #33 Add bsd and linux sed co...

Oct 18, 2024

Download .zip

What's Changed

Implement LiteREST: A lightweight SQLite-based REST API by @stritt in #10 Support SQLite file dumps by @Brayden in #20 Folder refactor for better separation by @Brayden in #21 Support...

What's Changed

chore: Remove unnecessary functions by @Brayden in #2 feat: Transaction support for query batching by @Brayden in #4 fix: Operation file hosts operation functions refactor by @Brayden...

Contributors

6 contributors by commits. Profile dekhne ke liye kisi bhi developer par click karein.