Skip to content

Commit 2154524

Browse files
committed
Merge branch 'main' into feat/go-gin-quickstart
2 parents 59c8aad + 595eab2 commit 2154524

14 files changed

Lines changed: 297 additions & 22 deletions

sqlite-cloud/_nav.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const sidebarNav: SidebarNavStruct = [
1313
{ title: "Node.js", filePath: "quick-start-node", type: "inner", level: 1 },
1414
{ title: "React", filePath: "quick-start-react", type: "inner", level: 1 },
1515
{ title: "React Native", filePath: "quick-start-react-native", type: "inner", level: 1 },
16+
{ title: "Apollo / GraphQL", filePath: "quick-start-apollo-graphql", type: "inner", level: 1 },
1617
{ title: "Next.js", filePath: "quick-start-next", type: "inner", level: 1 },
1718
{ title: "Django", filePath: "quick-start-django", type: "inner", level: 1 },
1819
{ title: "Flask", filePath: "quick-start-flask", type: "inner", level: 1 },
@@ -59,14 +60,14 @@ const sidebarNav: SidebarNavStruct = [
5960
{ filePath: 'sqlite-cloud/sdks/c/SQCloudResultDump', type: "inner", level: 2 },
6061

6162
{ title: "Rowset APIs", type: "inner", level: 1 },
62-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetValueType', type: "inner", level: 3 },
63-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetColumnName', type: "inner", level: 3 },
64-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetValue', type: "inner", level: 3 },
65-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetInt32Value', type: "inner", level: 3 },
66-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetInt64Value', type: "inner", level: 3 },
67-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetFloatValue', type: "inner", level: 3 },
68-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetDoubleValue', type: "inner", level: 3 },
69-
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetDump', type: "inner", level: 3 },
63+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetValueType', type: "inner", level: 2 },
64+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetColumnName', type: "inner", level: 2 },
65+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetValue', type: "inner", level: 2 },
66+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetInt32Value', type: "inner", level: 2 },
67+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetInt64Value', type: "inner", level: 2 },
68+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetFloatValue', type: "inner", level: 2 },
69+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetDoubleValue', type: "inner", level: 2 },
70+
{ filePath: 'sqlite-cloud/sdks/c/SQCloudRowsetDump', type: "inner", level: 2 },
7071

7172

7273
{ title: "Array APIs", type: "inner", level: 1 },
@@ -164,6 +165,9 @@ const sidebarNav: SidebarNavStruct = [
164165
{ title: 'Introduction', type: "inner", filePath: "sdk-php-introduction", level: 1 },
165166
{ title: "Methods", filePath: "sdk-php-methods", type: "inner", level: 1 },
166167

168+
{ title: "Swift", type: "inner", level: 0 },
169+
{ title: 'Introduction', type: "inner", filePath: "sdk-swift-introduction", level: 1 },
170+
167171
{ title: "Reference", type: "secondary", icon: "docs-ref" },
168172
{ title: "Server-side Commands", type: "inner", level: 0 },
169173
{ title: "Introduction", filePath: "server-side-commands", type: "inner", level: 1 },
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
---
2+
title: Apollo / GraphQL Quick Start Guide
3+
description: Get started with SQLite Cloud using Apollo and GraphQL.
4+
category: getting-started
5+
status: publish
6+
slug: quick-start-apollo-graphql
7+
---
8+
9+
In this quickstart, we will show you how to get started with SQLite Cloud and Apollo/GraphQL by writing a simple GraphQL wrapper around a SQLite Cloud database connection.
10+
11+
1. **Set up a SQLite Cloud account**
12+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
13+
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
14+
15+
2. **Install the necessary dependencies**
16+
- In your terminal run the following commands to install a new Apollo Server app.
17+
18+
```bash
19+
mkdir sqlc-quickstart
20+
cd sqlc-quickstart
21+
npm install apollo-server graphql
22+
```
23+
24+
3. **Create a new Apollo Server app**
25+
- Create a new file called `server.js` and add the following code.
26+
- Import the necessary packages, and instantiate a new Database connection.
27+
```js
28+
import { ApolloServer } from '@apollo/server';
29+
import { startStandaloneServer } from '@apollo/server/standalone';
30+
import { Database } from '@sqlitecloud/drivers';
31+
32+
const connStr = '<your-connection-string>'
33+
34+
const db = new Database(connStr)
35+
```
36+
- Next, define your GraphQL schema and resolvers.
37+
```js
38+
const typeDefs = `#graphql
39+
type Album {
40+
AlbumId: Int
41+
Title: String
42+
ArtistId: Int
43+
}
44+
45+
type Artist {
46+
ArtistId: Int
47+
Name: String
48+
}
49+
50+
type Track {
51+
TrackId: Int
52+
Name: String
53+
AlbumId: Int
54+
MediaTypeId: Int
55+
GenreId: Int
56+
Composer: String
57+
Milliseconds: Int
58+
Bytes: Int
59+
UnitPrice: Float
60+
}
61+
62+
type Genre {
63+
GenreId: Int
64+
Name: String
65+
}
66+
67+
type MediaType {
68+
MediaTypeId: Int
69+
Name: String
70+
}
71+
72+
type Join {
73+
AlbumId: Int
74+
Title: String
75+
ArtistName: String
76+
}
77+
78+
type Query {
79+
albums: [Album]
80+
artists: [Artist]
81+
tracks: [Track]
82+
genres: [Genre]
83+
mediaTypes: [MediaType]
84+
joins: [Join]
85+
artist(name: String): Artist
86+
albumsByArtist(artistId: Int): [Album]
87+
}
88+
89+
type Mutation {
90+
createArtist(name: String): Artist
91+
createAlbum(title: String, artistId: Int): Album
92+
}
93+
`;
94+
95+
const resolvers = {
96+
Query: {
97+
albums: async () => {
98+
return await db.sql`SELECT * FROM albums`;
99+
},
100+
artists: async () => {
101+
return await db.sql`SELECT * FROM artists`;
102+
},
103+
tracks: async () => {
104+
return await db.sql`SELECT * FROM tracks`;
105+
},
106+
genres: async () => {
107+
return await db.sql`SELECT * FROM genres`;
108+
},
109+
mediaTypes: async () => {
110+
return await db.sql`SELECT * FROM media_types`;
111+
},
112+
artist: async (_, { name }) => {
113+
const res = await db.sql`SELECT * FROM artists WHERE Name LIKE ${name};`;
114+
if (res.length === 0) return null;
115+
return res[0];
116+
},
117+
albumsByArtist: async (_, { artistId }) => {
118+
return await db.sql`SELECT albums.AlbumId, albums.Title FROM albums INNER JOIN artists ON albums.ArtistId = artists.ArtistId WHERE artists.ArtistId = ${artistId}`;
119+
},
120+
},
121+
Mutation: {
122+
createArtist: async (_, { name }) => {
123+
const res =
124+
await db.sql`INSERT INTO artists (Name) VALUES (${name})`;
125+
if (res.changes === 0) return null;
126+
return { ArtistId: res.lastID, Name: name };
127+
},
128+
createAlbum: async (_, { title, artistId }) => {
129+
const res =
130+
await db.sql`INSERT INTO albums (Title, ArtistId) VALUES (${title}, ${artistId})`;
131+
if (res.changes === 0) return null;
132+
return {
133+
AlbumId: res.lastID,
134+
Title: title,
135+
ArtistId: artistId,
136+
};
137+
},
138+
},
139+
};
140+
```
141+
142+
- Lastly, pass the GraphQLL type definitions and resolvers into a new ApolloServer instance, and start the server.
143+
```js
144+
const server = new ApolloServer({ typeDefs, resolvers });
145+
146+
const { url } = await startStandaloneServer(server, {
147+
listen: { port: 4000 },
148+
context: async () => ({ db })
149+
});
150+
151+
console.log(`🚀 Server ready at: ${url}`);
152+
```
153+
154+
4. **Run your app**
155+
- In your terminal, run the following command to start your Apollo Server.
156+
```bash
157+
node server.js
158+
```
159+
160+
5. **Query your data**
161+
- Open your browser and navigate to `http://localhost:4000` to access the Apollo GraphQL Playground.
162+
- Use the following queries to interact with your SQLite Cloud database.
163+
164+
Read operation:
165+
```graphql
166+
query {
167+
albums {
168+
AlbumId
169+
Title
170+
ArtistId
171+
}
172+
}
173+
```
174+
175+
Write operation:
176+
```graphql
177+
mutation {
178+
createArtist(name: "New Artist") {
179+
ArtistId
180+
Name
181+
}
182+
}
183+
```
184+
185+
And that's it! You've successfully built an Apollo/GraphQL server that reads and writes data to a SQLite Cloud database.
186+
187+
For the full code example, see the [SQLite Cloud Apollo/GraphQL example repo](https://github.com/sqlitecloud/examples/tree/main/graphql-apollo/server).

sqlite-cloud/quick-start-cdn.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we demonstrate how to locally serve the SQLite Cloud JS Driv
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616

1717
2. **Create a JavaScript / TypeScript app**

sqlite-cloud/quick-start-django.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ slug: quick-start-django
99
In this quickstart, we will show you how to get started with SQLite Cloud and Django by building a simple application that connects to and reads from a SQLite Cloud database.
1010

1111
1. **Set up a SQLite Cloud account**
12-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
12+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1313
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1414

1515
2. **Create a Django app**

sqlite-cloud/quick-start-flask.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and Fl
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616

1717
2. **Create a Flask app**

sqlite-cloud/quick-start-next.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and Ne
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616
2. **Create a Next.js app**
1717
- Create a Next app using ```create-next-app```. The following command creates a very simple app (JS, no Tailwind, uses the latest App Router) to keep the focus on querying the data.

sqlite-cloud/quick-start-node.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and No
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616
2. **Create a Node.js app**
1717
- Navigate to your target directory and run the following command to initialize your Node.js app and install the necessary depedencies:

sqlite-cloud/quick-start-php-laravel.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and PH
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616

1717
2. **Create a Laravel app**

sqlite-cloud/quick-start-prisma.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and Pr
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616
2. **Create a Next.js app**
1717
- Create a Next app using ```create-next-app```. The following command creates a very simple app (JS, no Tailwind, uses the latest App Router) to keep the focus on querying the data.

sqlite-cloud/quick-start-react-native.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ In this quickstart, we will show you how to get started with SQLite Cloud and Re
1111
---
1212

1313
1. **Set up a SQLite Cloud account**
14-
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new database.
14+
- If you haven't already, [sign up for a SQLite Cloud account](https://sqlitecloud.io/register) and create a new project.
1515
- In this guide, we will use the sample datasets that come pre-loaded with SQLite Cloud.
1616

1717
2. **Create a React Native project**

0 commit comments

Comments
 (0)