Skip to content

Commit 8aec7f5

Browse files
authored
Merge pull request #109 from sqlitecloud/jacob/update-architecture
Staging test - Jacob/update architecture
2 parents bcf5dc5 + af74b30 commit 8aec7f5

28 files changed

+1373
-152
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
---
2-
title: Scaling
3-
description: How to scale your SQLite Cloud cluster.
4-
category: platform
5-
status: publish
6-
slug: scaling
7-
---
81

2+
3+
## Architecture
4+
SQLite Cloud uses the [Raft](https://raft.github.io) consensus algorithm to distribute your data changes across a cluster of computing systems, ensuring that each node in the cluster agrees upon the same series of state transitions. Raft implements consensus with a leader approach.
5+
6+
SQLite Cloud is written in ANSI C and GO, and it works on most POSIX systems (Linux, *BSD, Mac OS X) and Windows.
7+
8+
SQLite Cloud supports all the SQLite features without any limitations, including ACID compliance and non-deterministic SQL statements.
9+
10+
## Scaling your cluster
911
SQLite Cloud leverages a customized Raft algorithm to maintain a robust and highly available database cluster. Here’s an essential guide on the node types within SQLite Cloud and strategic tips for scaling your cluster effectively.
1012

1113
## Overview of Node types

sqlite-cloud/_nav.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import type { SidebarNavStruct } from "@docs-website/types/sidebar-navigation";
22

33
const sidebarNav: SidebarNavStruct = [
44
{ title: "", type: "primary" },
5-
{ title: "Getting Started", filePath:"getting-started", type: "secondary", icon: "docs-star" },
6-
{ title: "Introduction", filePath:"introduction", type: "inner", level: 0 }, // should be index page for /docs and highlight "introduction" in nav
7-
{ title: "Fundamentals", type: "inner", level: 0 },
5+
{ title: "Introduction", type: "secondary", icon: "docs-star" },
6+
{ title: "Getting Started", href: "/docs/sqlite-cloud", type: "inner", level: 0 },
87
{ title: "Connecting", filePath: "connect-cluster", type: "inner", level: 1 },
98
{ title: "Creating a database", filePath: "create-database", type: "inner", level: 1 },
109
{ title: "Writing data", filePath: "write-data", type: "inner", level: 1 },
@@ -17,11 +16,14 @@ const sidebarNav: SidebarNavStruct = [
1716
{ title: "Next.js", filePath: "quick-start-next", type: "inner", level: 1 },
1817
{ title: "Django", filePath: "quick-start-django", type: "inner", level: 1 },
1918
{ title: "Flask", filePath: "quick-start-flask", type: "inner", level: 1 },
19+
{ title: "SQLAlchemy", filePath: "quick-start-sqlalchemy-orm", type: "inner", level: 1 },
2020
{ title: "Streamlit", filePath: "quick-start-streamlit", type: "inner", level: 1 },
2121
{ title: "PHP / Laravel", filePath: "quick-start-php-laravel", type: "inner", level: 1 },
2222
{ title: "Gin", filePath: "quick-start-gin", type: "inner", level: 1 },
2323
{ title: "Tutorials", type: "inner", level: 0 },
2424
{ title: "Geopoly", filePath: "tutorial-geopoly", type: "inner", level: 1 },
25+
{ title: "Integrations", type: "inner", level: 0 },
26+
{ title: "Knex.js", filePath: "knex-integration", type: "inner", level: 1 },
2527

2628
{ title: "Platform", filePath:"platform", type: "secondary", icon: "docs-plat" },
2729
{ title: "Edge Functions", filePath: "edge-functions", type: "inner", level: 0 },
@@ -36,7 +38,6 @@ const sidebarNav: SidebarNavStruct = [
3638
{ title: "Weblite", filePath: "weblite", type: "inner", level: 0 },
3739
// { title: "Storage", type: "inner", level: 0 },
3840
// { title: "Partitioning", type: "inner", level: 0 },
39-
{ title: "Settings", filePath: "settings", type: "inner", level: 0 },
4041

4142
{ title: "SDKs", filePath:"sdks", type: "secondary", icon: "docs-sdk" },
4243
{ title: "C/C++", type: "inner", level: 0 },
@@ -162,6 +163,7 @@ const sidebarNav: SidebarNavStruct = [
162163
{ title: 'Introduction', type: "inner", filePath: "sdk-python-introduction", level: 1 },
163164
{ title: "Django", ref: "/docs/quick-start-django", type: "inner", level: 1 },
164165
{ title: "Flask", ref: "/docs/quick-start-flask", type: "inner", level: 1 },
166+
{ title: "SQLAlchemy", ref: "/docs/quick-start-sqlalchemy-orm", type: "inner", level: 1 },
165167

166168
{ title: "Go", type: "inner", level: 0 },
167169
{ title: 'Introduction', type: "inner", filePath: "sdk-go-introduction", level: 1 },

sqlite-cloud/connect-cluster.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ slug: connect-cluster
88

99
SQLite databases in SQLite Cloud are distributed across a cluster of nodes. Each cluster comes with a multi-region load balancer that routes traffic to the nearest appropriate node.
1010

11-
For this reason, we strongly recommend connecting to your cluster via your project connection string. To retrieve your project connection string, navigate to the **Nodes** page and click on any node.
12-
{/* ![Project connection string modal](@docs-website-assets/connect-cluster-1.png) */}
13-
14-
Copy the connection string and use it with a client library to connect to your cluster.
11+
Click "Connect" in the bottom left-hand corner of your dashboard to get your connection string to use with a SQLite Cloud client library.
1512

1613
## Connecting with JavaScript
1714
Here's an example of how you can connect to your cluster using the `@sqlitecloud/drivers` JavaScript client library:
@@ -63,4 +60,5 @@ conn.close()
6360
```
6461

6562
## Next Steps
63+
- [Creating a database](/docs/create-database)
6664
- [Writing data](/docs/write-data)

sqlite-cloud/create-database.mdx

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ status: publish
66
slug: create-database
77
---
88

9-
SQLite Cloud allows you to import existing SQLite Databases, or create a new database in SQLite Cloud by importing an existing SQLite database, or using the SQLite Cloud UI, API, or client libraries.
9+
You can import an existing SQLite databases, or create new databases using the SQLite Cloud UI, API, or client libraries.
1010

11-
## Importing an existing SQLite database
12-
SQLite Cloud allows you to import existing SQLite databases into the platform.
11+
## Uploading an existing SQLite Database
12+
### Via HTTP API
13+
You can upload an existing SQLite database to your cluster using the SQLite Cloud UI or the Weblite API.
1314

14-
Note that you can download, modify, and re-upload the database file at any time. You can also upload encrypted SQLite databases if you used the official SEE SQLite encryption extension.
15+
To upload a local SQLite database via weblite, make a POST request to the `/v2/weblite/<database-name>.sqlite` endpoint.
1516

17+
```bash
18+
curl -X 'POST' \
19+
'https://<your-project-id>.sqlite.cloud:8090/v2/weblite/<database-name>.sqlite' \
20+
-H 'accept: application/json' \
21+
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
22+
-d ''
23+
```
24+
25+
To upload a local SQLite database via the SQLite Cloud UI, navigate to the Database tab in the left-hand navigation. Click the "Upload Database" button and select your local SQLite database.
26+
27+
### Via Dashboard UI
1628
To import a database from the UI, navigate to the Databases tab and click the "Upload Database" button.
1729
![Dashbord Upload Database](@docs-website-assets/introduction/dashboard_upload_db.png)
1830

@@ -27,7 +39,7 @@ To create a new database from the SQLite Cloud UI, navigate to the Databases tab
2739
The default encoding is set to UTF-8, and the default page size is 4096KB.
2840

2941
### From the API
30-
To create a new database or upload an existing database via [Weblite](#), our REST API, you can make a request with the following parameters:
42+
To create a new database or upload an existing database via [Weblite](/docs/weblite), our REST API, you can make a request with the following parameters:
3143
```bash
3244
curl -X 'POST' \
3345
'https://<your-project-id>.sqlite.cloud:8090/v2/weblite/<database-name>.sqlite' \
@@ -37,17 +49,32 @@ curl -X 'POST' \
3749
```
3850

3951
### From client libraries
40-
To create a new database from a client library, use the CREATE DATABASE command.
52+
To create a new database from a client library, connect to your cluster using a connection string without a specified database.
53+
54+
Then, use the CREATE DATABASE command to create a new database.
55+
56+
To start using the database within the connection, you can use the `USE DATABASE` command.
4157

4258
```javascript
4359
import { Database } from '@sqlitecloud/drivers';
44-
60+
// note that no database name is specified in the connection string path
4561
const db = new Database('sqlitecloud://<your-project-id>.sqlite.cloud:<your-host-port>?apikey=<your-api-key>')
4662

4763
const createDatabase = async () => await db.sql`CREATE DATABASE <database-name>;`;
4864

4965
createDatabase().then((res) => console.log(res));
5066

5167
// "OK"
68+
69+
db.exec('USE DATABASE <database-name>;')
70+
71+
// now you can use the database
72+
const fetchAlbums = async () => await db.exec`SELECT * FROM albums;`;
73+
74+
fetchAlbums().then((albums) => console.log(albums));
75+
76+
// [{ Title: 'For Those About To Rock We Salute You', ... }, ...]
5277
```
5378

79+
## Next Steps
80+
- [Writing data](/docs/write-data)

sqlite-cloud/index.mdx

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
---
2-
title: Getting Started
3-
description: Index page for getting started section
2+
title: Getting Started with SQLite Cloud
3+
description: SQLite Cloud is a distributed relational database system built on top of the SQLite database engine.
44
category: getting-started
55
status: publish
6-
icon: docs-star
7-
slug: getting-started
86
---
9-
import IndexPage from "@docs-website-components/Docs/IndexPage.astro"
107

11-
export const introduction = "SQLite Cloud is a distributed relational database system built on top of the SQLite database engine. It has been specifically designed from the ground up to ensure the strong consistency of your data across all nodes in a cluster while simultaneously managing the technical aspects of scaling, security, and data distribution."
8+
## Overview
9+
**SQLite Cloud** is a managed, distributed relational database system built on top of the SQLite database engine.
1210

13-
export const sections = [
14-
{
15-
icon: "curvedArrow",
16-
title: "Introduction",
17-
description: "SQLite Cloud introduction and getting started guide.",
18-
href: "/docs/introduction",
19-
},
20-
{
21-
icon: "twoColsGrid",
22-
title: "Fundamentals",
23-
description: "Learn how to connect to a cluster and start using SQLite Cloud.",
24-
href: "/docs/connect-cluster",
25-
},
26-
{
27-
icon: "puzzle",
28-
title: "Quick start guide",
29-
description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
30-
href: "/docs/quick-start-cdn",
31-
}
32-
]
11+
It has been designed from the ground up to ensure strong consistency across all nodes in a cluster while simultaneously managing the technical aspects of scaling, security, and data distribution. This ensures that you can focus on your core tasks while relying on SQLite Cloud to handle the complexities of managing your databases.
3312

13+
SQLite Cloud is built on the open source SQLite engine, ensuring complete feature parity. You get all of SQLite's core strengths: ACID compliance, support for complex SQL operations, and compatibility with the rich SQLite extension ecosystem.
3414

35-
<IndexPage introduction={introduction} sections={sections} />
15+
You can access SQLite Cloud from the most popular programming languages or its REST API.
16+
17+
Like SQLite, each database in SQLite Cloud is a separate file, giving you flexible deployment options:
18+
19+
* Create separate databases for each customer in a multi-tenant application
20+
* Share a single database among multiple users with built-in access controls
21+
* Mix both approaches based on your application's needs
22+
23+
### Features
24+
SQLite Cloud provides a comprehensive suite of tools for building realtime, local-first, edge AI applications.
25+
* **[Webhooks](/docs/webhooks)**: Trigger edge functions or send change payloads via HTTP, Websockets, or on database events like INSERT, UPDATE, and DELETE.
26+
* **[Edge Functions](/docs/edge-functions)**: Run serverless functions on the same nodes that store your data for lightning-fast data access.
27+
* **[Pub/Sub](/docs/pub-sub)**: Subscribe to changes in your database to replicate data, power notifications, and build multiplayer experiences.
28+
* **[Weblite](/docs/weblite)**: Autogenerated REST APIs to interact with the SQLite Cloud platform.
29+
* **[Query Analyzer](/docs/analyzer)**: Receive optimization recommendations for your queries to improve performance.

sqlite-cloud/knex-integration.mdx

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
title: Knex.js Integration
3+
description: Integrate SQLite Cloud with Knex.js, a popular SQL query builder.
4+
category: getting-started
5+
status: publish
6+
slug: knex-integration
7+
---
8+
9+
In this tutorial, we'll show you how to connect your TypeScript application to a SQLite Cloud database using the popular SQL builder, [Knex.js](https://knexjs.org/).
10+
11+
---
12+
13+
**Prerequisites**
14+
15+
- Node.js and npm installed on your system
16+
- A SQLite Cloud account (you can sign up for a free account [here](https://sqlitecloud.io/register))
17+
18+
1. **How to connect**
19+
20+
- Create a Knex.js instance that uses the SQLite Cloud JavaScript driver to connect to your database.
21+
22+
```typescript
23+
import 'dotenv/config'
24+
import { knex } from 'knex'
25+
26+
const Client_SQLite3 = require('knex/lib/dialects/sqlite3')
27+
28+
// client will have sqlite3 dialect, but will use sqlitecloud-js driver
29+
class Client_Libsql extends Client_SQLite3 {
30+
_driver() {
31+
return require('@sqlitecloud/drivers')
32+
}
33+
}
34+
35+
// Create a Knex.js instance with the custom SQLite3 client
36+
const db = knex({
37+
client: Client_Libsql as any,
38+
connection: {
39+
filename: process.env.DATABASE_URL as string
40+
}
41+
})
42+
```
43+
44+
2. **Basic Usage**
45+
46+
In this example, we will use the sample datasets that come pre-loaded with SQLite Cloud.
47+
48+
- Initialize a new Node project:
49+
50+
```bash
51+
npm init -y
52+
```
53+
54+
- Install the required dependencies:
55+
56+
```bash
57+
npm install @sqlitecloud/drivers knex dotenv --save
58+
```
59+
60+
- Install the necessary development dependencies:
61+
62+
```bash
63+
npm install @types/node nodemon ts-node typescript --save-dev
64+
```
65+
66+
- Create a `.env` file in the root of your project and add your SQLite Cloud connection string:
67+
68+
```bash
69+
DATABASE_URL="sqlitecloud://{USER}:{PASSWORD}@{HOST}.sqlite.cloud:8860"
70+
```
71+
72+
Replace `{USER}`, `{PASSWORD}`, and `{HOST}` with your actual SQLite Cloud credentials and server hostname.
73+
74+
- Create a `tsconfig.json` file to configure your TypeScript compiler:
75+
76+
```bash
77+
tsc --init
78+
```
79+
80+
- Create a new file called `example.ts` and add the following code:
81+
82+
```typescript
83+
import 'dotenv/config'
84+
import { knex } from 'knex'
85+
86+
const Client_SQLite3 = require('knex/lib/dialects/sqlite3')
87+
88+
class Client_Libsql extends Client_SQLite3 {
89+
_driver() {
90+
return require('@sqlitecloud/drivers')
91+
}
92+
}
93+
94+
console.assert(process.env.DATABASE_URL, 'Define DATABASE_URL environment variable')
95+
96+
const db = knex({
97+
client: Client_Libsql as any,
98+
connection: {
99+
filename: process.env.DATABASE_URL as string
100+
}
101+
})
102+
103+
db.raw('USE DATABASE chinook.sqlite; SELECT * FROM customers')
104+
.then(result => {
105+
console.log(`Connected to database via knex and received ${result.length} rows`)
106+
console.log(JSON.stringify(result, null, 2))
107+
db.destroy()
108+
})
109+
.catch(err => {
110+
console.error(err)
111+
db.destroy()
112+
})
113+
```
114+
115+
- Update your `package.json` file to include a script for running the example:
116+
117+
```bash
118+
{
119+
"scripts": {
120+
"dev": "nodemon --exec ts-node example.ts"
121+
}
122+
}
123+
```
124+
125+
- Start the development server:
126+
127+
```bash
128+
npm run dev
129+
```
130+
131+
This will run the `example.ts` file using `ts-node` and will automatically restart the server when you make changes to your code.
132+
133+
- Observe the output in the console, which should display the customer data fetched from the SQLite Cloud database.
134+
```bash
135+
[
136+
{
137+
"CustomerId": 1,
138+
"FirstName": "Luís",
139+
"LastName": "Gonçalves",
140+
"Company": "Embraer - Empresa Brasileira de Aeronáutica S.A.",
141+
"Address": "Av. Brigadeiro Faria Lima, 2170",
142+
"City": "São José dos Campos",
143+
"State": "SP",
144+
"Country": "Brazil",
145+
"PostalCode": "12227-000",
146+
"Phone": "+55 (12) 3923-5555",
147+
"Fax": "+55 (12) 3923-5566",
148+
"Email": "[email protected]",
149+
"SupportRepId": 3
150+
},
151+
]
152+
```
153+
154+
And that's it! You've successfully connected your TypeScript application to a SQLite Cloud database using Knex.js.

sqlite-cloud/platform/backups.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ slug: backups
77
---
88

99
## Overview
10-
Backups provide a robust solution for mitigating data loss and resolving data corruption issues.
10+
Backups provide a robust solution for mitigating data loss and resolving data corruption issues. Backups are available for databases in all [Pro and Scale](https://www.sqlitecloud.io/pricing) projects.
1111

1212
SQLite Cloud creates a full snapshot backup of your data once a day, and stores incremental changes once per second, on commodity object storage.
1313

0 commit comments

Comments
 (0)