Skip to content

Commit 89343c8

Browse files
committed
feat: merge local-libsql into the libsql command
1 parent 2479049 commit 89343c8

8 files changed

Lines changed: 52 additions & 122 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ Single binary, single command SQL database explorer. SQL studio supports *SQLite
1212
sql-studio sqlite [sqlite_db]
1313
```
1414

15-
### Remote libSQL Server
15+
### libSQL
1616

1717
```bash
18-
sql-studio libsql [url] [auth_token]
19-
```
20-
21-
### Local SQLite DB with libSQL driver
22-
23-
```bash
24-
sql-studio local-libsql [database]
18+
sql-studio libsql [database] [auth_token]
2519
```
2620

2721
### PostgreSQL Server
Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "libSQL"
3-
description: "Connect SQL Studio to a remote libSQL (Turso) server."
3+
description: "Connect SQL Studio to a libSQL database."
44
icon: "turso"
55
openGraph:
66
images:
@@ -15,29 +15,40 @@ twitter:
1515

1616
# libSQL
1717

18-
Connect to a remote SQLite database via the libSQL protocol (used by [Turso](https://turso.tech)).
18+
Connect to a libSQL database, used by [Turso](https://turso.tech).
1919

2020
## Usage
2121

2222
```bash
23-
sql-studio libsql <URL> <AUTH_TOKEN>
23+
sql-studio libsql <DATABASE> [AUTH_TOKEN]
2424
```
2525

2626
## Arguments
2727

2828
| Argument | Description | Env Var |
2929
|----------|-------------|---------|
30-
| `URL` | libSQL server address | `URL` |
31-
| `AUTH_TOKEN` | Authentication token | `AUTH_TOKEN` |
30+
| `DATABASE` | Path to a local SQLite database file, or the URL of a libSQL server | `DATABASE` |
31+
| `AUTH_TOKEN` | Authentication token, only used when connecting to a server | `AUTH_TOKEN` |
32+
33+
## Notes
34+
35+
- `DATABASE` is treated as a server URL when it starts with `libsql://`, `http://`, `https://`, `ws://` or `wss://`. Anything else is opened as a local file.
36+
- The local mode is useful when you need libSQL-specific features that the standard SQLite driver doesn't provide.
3237

3338
## Examples
3439

3540
```bash
41+
# Open a local database file
42+
sql-studio libsql ./my-database.db
43+
3644
# Connect to a Turso database
3745
sql-studio libsql libsql://my-db-myorg.turso.io my-auth-token
3846

47+
# Connect to a local libSQL server without authentication
48+
sql-studio libsql http://127.0.0.1:8080
49+
3950
# Using environment variables
40-
export URL="libsql://my-db-myorg.turso.io"
51+
export DATABASE="libsql://my-db-myorg.turso.io"
4152
export AUTH_TOKEN="my-auth-token"
42-
sql-studio libsql "$URL" "$AUTH_TOKEN"
53+
sql-studio libsql
4354
```

‎docs/app/docs/databases/local-libsql/page.mdx‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎docs/app/docs/databases/page.mdx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ SQL Studio supports a wide range of SQL databases and file formats. Each databas
2222
| Database | Subcommand | Type |
2323
|----------|-----------|------|
2424
| [SQLite](/docs/databases/sqlite) | `sqlite` | Local file |
25-
| [libSQL](/docs/databases/libsql) | `libsql` | Remote server |
26-
| [Local libSQL](/docs/databases/local-libsql) | `local-libsql` | Local file (libSQL driver) |
25+
| [libSQL](/docs/databases/libsql) | `libsql` | libSQL |
2726
| [PostgreSQL](/docs/databases/postgresql) | `postgres` | Remote server |
2827
| [MySQL / MariaDB](/docs/databases/mysql) | `mysql` | Remote server |
2928
| [DuckDB](/docs/databases/duckdb) | `duckdb` | Local file |

‎docs/app/docs/page.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SQL Studio is a **single binary, single command** web-based SQL database explore
2020
## Supported Databases
2121

2222
- **SQLite** — local `.db` / `.sqlite` files
23-
- **libSQL** — remote libSQL (Turso) servers
23+
- **libSQL** — libSQL databases
2424
- **PostgreSQL** — any PostgreSQL-compatible server
2525
- **MySQL / MariaDB** — MySQL and MariaDB servers
2626
- **DuckDB** — local `.duckdb` analytics files

‎docs/app/page.tsx‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import { CopyButton } from "./copy-button";
55
export const metadata: Metadata = {
66
title: "SQL Studio — Single Binary SQL Database Explorer",
77
description:
8-
"Single binary SQL database explorer. 10 databases. One interface. No config files.",
8+
"Single binary SQL database explorer. 9 databases. One interface. No config files.",
99
openGraph: {
1010
title: "SQL Studio",
1111
description:
12-
"Single binary SQL database explorer. 10 databases. One interface.",
12+
"Single binary SQL database explorer. 9 databases. One interface.",
1313
images: [{ url: "/og/index.png", width: 1200, height: 630 }],
1414
},
1515
twitter: {
1616
card: "summary_large_image",
1717
title: "SQL Studio",
1818
description:
19-
"Single binary SQL database explorer. 10 databases. One interface.",
19+
"Single binary SQL database explorer. 9 databases. One interface.",
2020
images: ["/og/index.png"],
2121
},
2222
};
@@ -48,8 +48,8 @@ const DATABASES = [
4848
},
4949
{
5050
name: "libSQL",
51-
command: "libsql [url] [token]",
52-
description: "Remote Turso",
51+
command: "libsql [db] [token]",
52+
description: "Turso",
5353
href: "/docs/databases/libsql",
5454
},
5555
{
@@ -76,12 +76,6 @@ const DATABASES = [
7676
description: "CSV files",
7777
href: "/docs/databases/csv",
7878
},
79-
{
80-
name: "Local libSQL",
81-
command: "local-libsql [db]",
82-
description: "Local libSQL",
83-
href: "/docs/databases/local-libsql",
84-
},
8579
];
8680

8781
const FEATURES = [
@@ -260,7 +254,7 @@ export default function LandingPage() {
260254
className="ld-up tw:mt-8 tw:max-w-md tw:text-sm tw:leading-relaxed"
261255
style={{ animationDelay: "0.35s", color: "var(--ss-muted)" }}
262256
>
263-
Single binary SQL database explorer. 10 databases. One interface.
257+
Single binary SQL database explorer. 9 databases. One interface.
264258
No config files.
265259
</p>
266260

‎docs/docs.config.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export default defineDocs({
134134
children: [
135135
{ slug: "sqlite" },
136136
{ slug: "libsql" },
137-
{ slug: "local-libsql" },
138137
{ slug: "postgresql" },
139138
{ slug: "mysql" },
140139
{ slug: "duckdb" },

‎src/main.rs‎

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,16 @@ enum Command {
4343
database: String,
4444
},
4545

46-
/// A remote SQLite database via libSQL.
46+
/// A libSQL database.
47+
#[command(alias = "local-libsql")]
4748
Libsql {
48-
/// libSQL server address
49+
/// Path to a local SQLite database file, or the URL of a libSQL server.
4950
#[arg(env)]
50-
url: String,
51-
52-
/// libSQL authentication token.
53-
#[arg(env)]
54-
auth_token: String,
55-
},
51+
database: String,
5652

57-
/// A local SQLite database via libSQL.
58-
LocalLibsql {
59-
/// Path to the sqlite database file to be opened with libSQL.
53+
/// libSQL authentication token. [only used when connecting to a server]
6054
#[arg(env)]
61-
database: String,
55+
auth_token: Option<String>,
6256
},
6357

6458
/// A PostgreSQL database.
@@ -146,12 +140,10 @@ async fn main() -> color_eyre::Result<()> {
146140
Command::Sqlite { database } => {
147141
AllDbs::Sqlite(sqlite::Db::open(database, args.timeout.into()).await?)
148142
}
149-
Command::Libsql { url, auth_token } => {
150-
AllDbs::Libsql(libsql::Db::open(url, auth_token, args.timeout.into()).await?)
151-
}
152-
Command::LocalLibsql { database } => {
153-
AllDbs::Libsql(libsql::Db::open_local(database, args.timeout.into()).await?)
154-
}
143+
Command::Libsql {
144+
database,
145+
auth_token,
146+
} => AllDbs::Libsql(libsql::Db::open(database, auth_token, args.timeout.into()).await?),
155147
Command::Postgres { url, schema } => {
156148
AllDbs::Postgres(postgres::Db::open(url, schema, args.timeout.into()).await?)
157149
}
@@ -1026,48 +1018,25 @@ mod libsql {
10261018
query_timeout: Duration,
10271019
}
10281020

1021+
fn is_remote(database: &str) -> bool {
1022+
["libsql://", "http://", "https://", "ws://", "wss://"]
1023+
.iter()
1024+
.any(|scheme| database.starts_with(scheme))
1025+
}
1026+
10291027
impl Db {
10301028
pub async fn open(
1031-
url: String,
1032-
auth_token: String,
1033-
query_timeout: Duration,
1034-
) -> color_eyre::Result<Self> {
1035-
let db = Builder::new_remote(url.to_owned(), auth_token)
1036-
.build()
1037-
.await?;
1038-
let conn = db.connect()?;
1039-
1040-
let tables = conn
1041-
.query(
1042-
r#"
1043-
SELECT count(*) FROM sqlite_master
1044-
WHERE type="table"
1045-
"#,
1046-
(),
1047-
)
1048-
.await?
1049-
.next()
1050-
.await?
1051-
.ok_or_eyre("no row returned from db")?
1052-
.get::<i32>(0)?;
1053-
1054-
tracing::info!(
1055-
"found {tables} table{} in {url}",
1056-
if tables == 1 { "" } else { "s" }
1057-
);
1058-
1059-
Ok(Self {
1060-
name: url,
1061-
query_timeout,
1062-
db: Arc::new(db),
1063-
})
1064-
}
1065-
1066-
pub async fn open_local(
10671029
database: String,
1030+
auth_token: Option<String>,
10681031
query_timeout: Duration,
10691032
) -> color_eyre::Result<Self> {
1070-
let db = Builder::new_local(&database).build().await?;
1033+
let db = if is_remote(&database) {
1034+
Builder::new_remote(database.clone(), auth_token.unwrap_or_default())
1035+
.build()
1036+
.await?
1037+
} else {
1038+
Builder::new_local(&database).build().await?
1039+
};
10711040
let conn = db.connect()?;
10721041

10731042
let tables = conn

0 commit comments

Comments
 (0)