Skip to content

Small 1.0 updates #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,70 @@ curl "https://$DEPLOYMENT_NAME.convex.site/api/listMessages/456"
curl -d '{ "author": "User 456", "body": "Hello world" }' \
-H 'content-type: application/json' "https://$DEPLOYMENT_NAME.convex.site/api/postMessage"
```

# What is Convex?

[Convex](https://convex.dev) is a hosted backend platform with a
built-in database that lets you write your
[database schema](https://docs.convex.dev/database/schemas) and
[server functions](https://docs.convex.dev/functions) in
[TypeScript](https://docs.convex.dev/typescript). Server-side database
[queries](https://docs.convex.dev/functions/query-functions) automatically
[cache](https://docs.convex.dev/functions/query-functions#caching--reactivity) and
[subscribe](https://docs.convex.dev/client/react#reactivity) to data, powering a
[realtime `useQuery` hook](https://docs.convex.dev/client/react#fetching-data) in our
[React client](https://docs.convex.dev/client/react). There are also
[Python](https://docs.convex.dev/client/python),
[Rust](https://docs.convex.dev/client/rust),
[ReactNative](https://docs.convex.dev/client/react-native), and
[Node](https://docs.convex.dev/client/javascript) clients, as well as a straightforward
[HTTP API](https://github.com/get-convex/convex-js/blob/main/src/browser/http_client.ts#L40).

The database support
[NoSQL-style documents](https://docs.convex.dev/database/document-storage) with
[relationships](https://docs.convex.dev/database/document-ids) and
[custom indexes](https://docs.convex.dev/database/indexes/)
(including on fields in nested objects).

The
[`query`](https://docs.convex.dev/functions/query-functions) and
[`mutation`](https://docs.convex.dev/functions/mutation-functions) server functions have transactional,
low latency access to the database and leverage our
[`v8` runtime](https://docs.convex.dev/functions/runtimes) with
[determinism guardrails](https://docs.convex.dev/functions/runtimes#using-randomness-and-time-in-queries-and-mutations)
to provide the strongest ACID guarantees on the market:
immediate consistency,
serializable isolation, and
automatic conflict resolution via
[optimistic multi-version concurrency control](https://docs.convex.dev/database/advanced/occ) (OCC / MVCC).

The [`action` server functions](https://docs.convex.dev/functions/actions) have
access to external APIs and enable other side-effects and non-determinism in
either our
[optimized `v8` runtime](https://docs.convex.dev/functions/runtimes) or a more
[flexible `node` runtime](https://docs.convex.dev/functions/runtimes#nodejs-runtime).

Functions can run in the background via
[scheduling](https://docs.convex.dev/scheduling/scheduled-functions) and
[cron jobs](https://docs.convex.dev/scheduling/cron-jobs).

Development is cloud-first, with
[hot reloads for server function](https://docs.convex.dev/cli#run-the-convex-dev-server) editing via the
[CLI](https://docs.convex.dev/cli). There is a
[dashbord UI](https://docs.convex.dev/dashboard) to
[browse and edit data](https://docs.convex.dev/dashboard/deployments/data),
[edit environment variables](https://docs.convex.dev/production/environment-variables),
[view logs](https://docs.convex.dev/dashboard/deployments/logs),
[run server functions](https://docs.convex.dev/dashboard/deployments/functions), and more.

There are built-in features for
[reactive pagination](https://docs.convex.dev/database/pagination),
[file storage](https://docs.convex.dev/file-storage),
[reactive search](https://docs.convex.dev/text-search),
[https endpoints](https://docs.convex.dev/functions/http-actions) (for webhooks),
[streaming import/export](https://docs.convex.dev/database/import-export/), and
[runtime data validation](https://docs.convex.dev/database/schemas#validators) for
[function arguments](https://docs.convex.dev/functions/args-validation) and
[database data](https://docs.convex.dev/database/schemas#schema-validation).

Everything scales automatically, and it’s [free to start](https://www.convex.dev/plans).
4 changes: 3 additions & 1 deletion convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.0.2.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand All @@ -15,6 +15,7 @@ import type {
FunctionReference,
} from "convex/server";
import type * as http from "../http";
import type * as init from "../init";
import type * as lib_honoWithConvex from "../lib/honoWithConvex";
import type * as messages from "../messages";

Expand All @@ -28,6 +29,7 @@ import type * as messages from "../messages";
*/
declare const fullApi: ApiFromModules<{
http: typeof http;
init: typeof init;
"lib/honoWithConvex": typeof lib_honoWithConvex;
messages: typeof messages;
}>;
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.0.2.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/dataModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.0.2.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.0.2.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.0.2.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
23 changes: 23 additions & 0 deletions convex/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { internalMutation } from "./_generated/server";

// Seed script to add a message if the table is empty
// This can be run automatically by modifying package.json
// scripts:
// "dev:init": "convex dev --until-success --run init",
// Or removed with:
// "dev:init": "convex dev --until-success",
export default internalMutation({
handler: async (ctx) => {
const exiting = await ctx.db.query("messages").first();
if (!exiting) {
await ctx.db.insert("messages", {
author: "Test User",
body: "Hello World",
});
await ctx.db.insert("messages", {
author: "World",
body: "Hello Test User",
});
}
},
});
24 changes: 9 additions & 15 deletions convex/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import { v } from "convex/values";
import { Doc } from "./_generated/dataModel";
import { internalMutation, internalQuery } from "./_generated/server";

export const listAll = internalQuery(
async ({ db }): Promise<Doc<"messages">[]> => {
return await db.query("messages").collect();
}
);
export const listAll = internalQuery({
handler: async (ctx): Promise<Doc<"messages">[]> => {
return await ctx.db.query("messages").collect();
},
});

export const listByAuthor = internalQuery({
args: { authorNumber: v.string() },
handler: async (
{ db },
{ authorNumber }: { authorNumber: string }
): Promise<Doc<"messages">[]> => {
const messages = await db.query("messages").collect();
handler: async (ctx, { authorNumber }): Promise<Doc<"messages">[]> => {
const messages = await ctx.db.query("messages").collect();
return messages.filter((message) => message.author.includes(authorNumber));
},
});
Expand All @@ -24,11 +21,8 @@ export const send = internalMutation({
body: v.string(),
author: v.string(),
},
handler: async (
{ db },
{ body, author }: { body: string; author: string }
) => {
handler: async (ctx, { body, author }) => {
const message = { body, author };
await db.insert("messages", message);
await ctx.db.insert("messages", message);
},
});
Loading