Skip to content

Commit 9bab646

Browse files
committed
Clone next convex app
1 parent 2594970 commit 9bab646

26 files changed

+4536
-1
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.next
2+
convex/_generated

.prettierrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false
4+
}

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
# discord-bot
1+
# Convex
2+
3+
This example demonstrates the Convex global state management framework.
4+
5+
## Deploy your own
6+
7+
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):
8+
9+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/convex&project-name=convex&repository-name=convex)
10+
11+
## How to use
12+
13+
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:
14+
15+
```bash
16+
npx create-next-app --example convex convex-app
17+
# or
18+
yarn create next-app --example convex convex-app
19+
# or
20+
pnpm create next-app --example convex convex-app
21+
```
22+
23+
Run
24+
25+
```bash
26+
npm run dev
27+
```
28+
29+
to run `next dev` and a Convex file watcher at the same time. This command will log you into Convex, so you'll need to create a Convex account if this is your first project.
30+
31+
Once everything is working, commit your code and deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
32+
33+
Use `npx convex deploy && npm run build` as the build command and set the `CONVEX_DEPLOY_KEY` environmental variable in Vercel ([Documentation](https://docs.convex.dev/getting-started/deployment/hosting/vercel)).

convex/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Welcome to your Convex functions directory!
2+
3+
Write your Convex functions here. See
4+
https://docs.convex.dev/using/writing-convex-functions for more.
5+
6+
A query function that takes two arguments looks like:
7+
8+
```typescript
9+
// myQueryFunction.ts
10+
import { query } from './_generated/server'
11+
12+
export default query(async ({ db }, first: number, second: string) => {
13+
// Validate arguments here.
14+
if (typeof first !== 'number' || first < 0) {
15+
throw new Error('First argument is not a non-negative number.')
16+
}
17+
if (typeof second !== 'string' || second.length > 1000) {
18+
throw new Error('Second argument is not a string of length 1000 or less.')
19+
}
20+
21+
// Query the database as many times as you need here.
22+
// See https://docs.convex.dev/using/database-queries to learn how to write queries.
23+
const documents = await db.query('tablename').collect()
24+
25+
// Write arbitrary JavaScript here: filter, aggregate, build derived data,
26+
// remove non-public properties, or create new objects.
27+
return documents
28+
})
29+
```
30+
31+
Using this query function in a React component looks like:
32+
33+
```typescript
34+
const data = useQuery('myQueryFunction', 10, 'hello')
35+
```
36+
37+
A mutation function looks like:
38+
39+
```typescript
40+
// myMutationFunction.ts
41+
import { mutation } from './_generated/server'
42+
43+
export default mutation(async ({ db }, first: string, second: string) => {
44+
// Validate arguments here.
45+
if (typeof first !== 'string' || typeof second !== 'string') {
46+
throw new Error('Both arguments must be strings')
47+
}
48+
49+
// Insert or modify documents in the database here.
50+
// Mutations can also read from the database like queries.
51+
const message = { body: first, author: second }
52+
const id = await db.insert('messages', message)
53+
54+
// Optionally, return a value from your mutation.
55+
return await db.get(id)
56+
})
57+
```
58+
59+
Using this mutation function in a React component looks like:
60+
61+
```typescript
62+
const mutation = useMutation('myMutationFunction')
63+
function handleButtonPress() {
64+
// fire and forget, the most common way to use mutations
65+
mutation('Hello!', 'me')
66+
// OR
67+
// use the result once the mutation has completed
68+
mutation('Hello!', 'me').then((result) => console.log(result))
69+
}
70+
```
71+
72+
The Convex CLI is your friend. See everything it can do by running
73+
`npx convex -h` in your project root directory. To learn more, launch the docs
74+
with `npx convex docs`.

convex/_generated/api.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated API.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex codegen`.
9+
* @module
10+
*/
11+
12+
import type { ApiFromModules } from "convex/api";
13+
import type * as listMessages from "../listMessages";
14+
import type * as sendMessage from "../sendMessage";
15+
16+
/**
17+
* A type describing your app's public Convex API.
18+
*
19+
* This `API` type includes information about the arguments and return
20+
* types of your app's query and mutation functions.
21+
*
22+
* This type should be used with type-parameterized classes like
23+
* `ConvexReactClient` to create app-specific types.
24+
*/
25+
export type API = ApiFromModules<{
26+
listMessages: typeof listMessages;
27+
sendMessage: typeof sendMessage;
28+
}>;

convex/_generated/clientConfig.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated development client configuration.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex codegen`.
9+
* @module
10+
*/
11+
12+
import type { ClientConfiguration } from "convex/browser";
13+
14+
/**
15+
* The DEV Convex client configuration.
16+
*
17+
* This configuration connects your client to your dev Convex deployment
18+
* when `npx convex dev` is running.
19+
*
20+
* To generate the production version, run `npx convex deploy`.
21+
*
22+
* Usage:
23+
*
24+
* ```ts
25+
* import clientConfig from "../convex/_generated/clientConfig";
26+
*
27+
* const convex = new ConvexReactClient(clientConfig);
28+
* ```
29+
*/
30+
declare const clientConfig: ClientConfiguration;
31+
export default clientConfig;

convex/_generated/clientConfig.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated development client configuration.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex codegen`.
9+
* @module
10+
*/
11+
12+
/**
13+
* The DEV Convex client configuration.
14+
*
15+
* This configuration connects your client to your dev Convex deployment
16+
* when `npx convex dev` is running.
17+
*
18+
* To generate the production version, run `npx convex deploy`.
19+
*
20+
* Usage:
21+
*
22+
* ```ts
23+
* import clientConfig from "../convex/_generated/clientConfig";
24+
*
25+
* const convex = new ConvexReactClient(clientConfig);
26+
* ```
27+
*/
28+
const clientConfig = {
29+
address: "http://localhost:8187",
30+
};
31+
export default clientConfig;

convex/_generated/dataModel.d.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated data model types.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex codegen`.
9+
* @module
10+
*/
11+
12+
import type {
13+
DataModelFromSchemaDefinition,
14+
DocumentMapFromSchemaDefinition,
15+
} from "convex/schema";
16+
import type { TableNamesInDataModel } from "convex/server";
17+
import { GenericId, GenericIdConstructor } from "convex/values";
18+
import schema from "../schema";
19+
20+
/**
21+
* The names of all of your Convex tables.
22+
*/
23+
export type TableNames = TableNamesInDataModel<DataModel>;
24+
25+
/**
26+
* The type of a document stored in Convex.
27+
*
28+
* @typeParam TableName - A string literal type of the table name (like "users").
29+
*/
30+
export type Document<TableName extends TableNames> =
31+
DocumentMapFromSchemaDefinition<typeof schema>[TableName];
32+
33+
/**
34+
* An identifier for a document in Convex.
35+
*
36+
* Convex documents are uniquely identified by their `Id`, which is accessible
37+
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling).
38+
*
39+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
40+
*
41+
* **Important**: Use `myId.equals(otherId)` to check for equality.
42+
* Using `===` will not work because two different instances of `Id` can refer
43+
* to the same document.
44+
*
45+
* @typeParam TableName - A string literal type of the table name (like "users").
46+
*/
47+
export type Id<TableName extends TableNames> = GenericId<TableName>;
48+
49+
/**
50+
* An identifier for a document in Convex.
51+
*
52+
* Convex documents are uniquely identified by their `Id`, which is accessible
53+
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling).
54+
*
55+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
56+
*
57+
* **Important**: Use `myId.equals(otherId)` to check for equality.
58+
* Using `===` will not work because two different instances of `Id` can refer
59+
* to the same document.
60+
*/
61+
export declare const Id: GenericIdConstructor<TableNames>;
62+
63+
/**
64+
* A type describing your Convex data model.
65+
*
66+
* This type includes information about what tables you have, the type of
67+
* documents stored in those tables, and the indexes defined on them.
68+
*
69+
* This type is used to parameterize methods like `queryGeneric` and
70+
* `mutationGeneric` to make them type-safe.
71+
*/
72+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;

convex/_generated/dataModel.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable */
2+
/**
3+
* Generated data model types.
4+
*
5+
* THIS CODE IS AUTOMATICALLY GENERATED.
6+
*
7+
* Generated by [email protected].
8+
* To regenerate, run `npx convex codegen`.
9+
* @module
10+
*/
11+
12+
import { GenericId } from "convex/values";
13+
14+
/**
15+
* An identifier for a document in Convex.
16+
*
17+
* Convex documents are uniquely identified by their `Id`, which is accessible
18+
* on the `_id` field. To learn more, see [Data Modeling](https://docs.convex.dev/using/data-modeling).
19+
*
20+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
21+
*
22+
* **Important**: Use `myId.equals(otherId)` to check for equality.
23+
* Using `===` will not work because two different instances of `Id` can refer
24+
* to the same document.
25+
*/
26+
export const Id = GenericId;

0 commit comments

Comments
 (0)