ian
ian
CCConvex Community
Created by ian on 9/18/2024 in #support-community
How can I re-use table validators?
If I define types in my table in my schema, how can I use them in functions and get the types?
14 replies
CCConvex Community
Created by ian on 3/23/2024 in #support-community
How to write SQL against a Convex data snapshot
You can use DuckDB to write SQL queries against a data snapshot. If you want to do some analytics against your current dataset, and don't want to set up streaming export, and want more than the interactive dashboard query[^1], you can install duckdb
$ brew install duckdb # Installs duckdb (mac)
$ npx convex export --prod --path ./snapshot.zip
$ unzip ./snapshot.zip
$ duckdb
D install 'json';
D load 'json';
D SELECT * from 'snapshot/myTable/documents.jsonl' LIMIT 1;
┌────────────────────┬─────────────┬───────────┬─────────────────────────────────┐
│ _creationTime │ _id │ someField │ otherTableId │
│ double │ varcharvarcharvarchar
├────────────────────┼─────────────┼───────────┼─────────────────────────────────┤
1705522240446.3655 │ js700yfk... │ foo │ 3cqbsxb8cexh8stz73be6f9w9hjqa28 │
└────────────────────┴─────────────┴───────────┴─────────────────────────────────┘
D SELECT someField, otherField from 'snapshot/myTable/documents.jsonl' as myTable
JOIN 'snapshot/otherTable/documents.jsonl' as otherTable
ON myTable.otherTableId = otherTable._id LIMIT 1;
┌───────────┬────────────┐
│ someField │ otherField │
varcharboolean
├───────────┼────────────┤
│ foo │ true │
└───────────┴────────────┘
$ brew install duckdb # Installs duckdb (mac)
$ npx convex export --prod --path ./snapshot.zip
$ unzip ./snapshot.zip
$ duckdb
D install 'json';
D load 'json';
D SELECT * from 'snapshot/myTable/documents.jsonl' LIMIT 1;
┌────────────────────┬─────────────┬───────────┬─────────────────────────────────┐
│ _creationTime │ _id │ someField │ otherTableId │
│ double │ varcharvarcharvarchar
├────────────────────┼─────────────┼───────────┼─────────────────────────────────┤
1705522240446.3655 │ js700yfk... │ foo │ 3cqbsxb8cexh8stz73be6f9w9hjqa28 │
└────────────────────┴─────────────┴───────────┴─────────────────────────────────┘
D SELECT someField, otherField from 'snapshot/myTable/documents.jsonl' as myTable
JOIN 'snapshot/otherTable/documents.jsonl' as otherTable
ON myTable.otherTableId = otherTable._id LIMIT 1;
┌───────────┬────────────┐
│ someField │ otherField │
varcharboolean
├───────────┼────────────┤
│ foo │ true │
└───────────┴────────────┘
[^1]: https://vimeo.com/925663954
1 replies
CCConvex Community
Created by ian on 3/15/2024 in #support-community
CRUD helper
For building crud operations, I made a helper recently: crud with an example here
26 replies
CCConvex Community
Created by ian on 1/4/2024 in #support-community
How to search by multiple fields?
@ckobasti writes: I want a search for people feature in my app, so my question is what is best method to search within single table by any parameter (not really any but username, firstName, lastName, etc.. something like instagram search)? I mean by multiple parameters
29 replies
CCConvex Community
Created by ian on 12/6/2023 in #support-community
Share code with multiple clients
@burnstony#1975 :
is it possible to export an application from the dashboard to files. I was actually wondering how to export everything else beside the data. the stuff that would probably be checked into git
11 replies
CCConvex Community
Created by ian on 8/11/2023 in #support-community
Pair with offline local-first library?
@FlipOneUp writes: What local-first, offline-capable JS/TS library can I use with Convex to make it a fully-offline-capable, auto-data-sync’ing tech stack?
34 replies
CCConvex Community
Created by ian on 8/11/2023 in #support-community
are IDs random & unique?
@Mikael Lirbank writes: Are the generated DB IDs unique and random (are they unpredictable), or just unique? Eg. are they safe to use as access tokens, or should I generate my own and store them in another field?
2 replies
CCConvex Community
Created by ian on 7/30/2023 in #support-community
Testing Authenticated Functions
@OccultSlolem writes: What's a good approach for writing tests for Convex actions, queries, and mutations, especially when those tests are dependent on auth state?
6 replies
CCConvex Community
Created by ian on 6/21/2023 in #support-community
Performance impact of re-using queries
@erquhart : I'm handling authorization by creating reusable queries that ensure authorization for the data they return, and each of them reuse this query:
export const getUser = async (auth: Auth, db: DatabaseReader) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Not authenticated')
}
const user = await db
.query('users')
.withIndex('byClerkId', (q) => q.eq('clerkId', identity.subject))
.unique()
if (!user) {
throw new Error('User not found')
}
return user
}
export const getUser = async (auth: Auth, db: DatabaseReader) => {
const identity = await auth.getUserIdentity()
if (!identity) {
throw new Error('Not authenticated')
}
const user = await db
.query('users')
.withIndex('byClerkId', (q) => q.eq('clerkId', identity.subject))
.unique()
if (!user) {
throw new Error('User not found')
}
return user
}
I don't know much about Convex's runtime, would a lot of identical calls to queries like this be expected to impact response times?
6 replies
CCConvex Community
Created by ian on 5/24/2023 in #support-community
User index not found / re-created
@simonjbest : Hi, I've been using your recommended code for authentication (https://docs.convex.dev/auth/database-auth) and have a by_token index on the users table defined in my schema.ts file. This has worked fine for some time but I'm now getting the error "Index users.by_token not found". It tries to add the index every time it deploys updated functions ( [+] users.by_token ["tokenIdentifier","_creationTime"] ) but I don't see the index on the Schema and Indexes page in the app. What do I need to do to get this working again?
11 replies
CCConvex Community
Created by ian on 4/24/2023 in #support-community
input validation type for paginationOpts?
What type should I use for input validation for paginationOpts?
2 replies
CCConvex Community
Created by ian on 4/21/2023 in #support-community
authorization support?
@Dima Utkin : "Convex currently has an authentication framework which verifies user identities. In the future we plan to add an authorization framework which will allow developers to define what data a user can access." how far is this on the roadmap? 🙂
15 replies
CCConvex Community
Created by ian on 4/14/2023 in #support-community
Pagination with take/skip instead of cursor?
@whoami : Hi team, I am wondering if there is a {take: number, skip: number} (basically the number of elements per page, and the start index where the query starts like here https://www.howtographql.com/typescript-helix/10-filtering-pagination-and-sorting/) API for handling the pagination without cursor? If not, what is the best way for me hack into this? Thanks!
11 replies
CCConvex Community
Created by ian on 4/8/2023 in #support-community
DB access from local script?
@Ethan Brown: Is there an example or any documentation for programmatically connecting to the database from a script I can run locally? That is, I want to have some script foo.js that makes db.<whatever> calls and then run it locally...any advice?
7 replies
CCConvex Community
Created by ian on 4/4/2023 in #support-community
Trigger an action from a query?
@punn Is there a way to listen to changes in a specific table and trigger an action based on those changes?
10 replies
CCConvex Community
Created by ian on 3/22/2023 in #support-community
Can your HTTP Endpoints support /path/:slug syntax?
And can do I do middleware, etc please?
2 replies
CCConvex Community
Created by ian on 3/22/2023 in #support-community
How to test React Components that use Convex?
Is there a mock React client or something I can use?
2 replies
CCConvex Community
Created by ian on 3/22/2023 in #support-community
How can I cancel /debounce/ retry scheduled functions?
I see you can schedule functions, but how would I cancel them, etc?
2 replies
CCConvex Community
Created by ian on 3/22/2023 in #support-community
Session tracking?
What's the recommended way to do session tracking in Convex?
4 replies
CCConvex Community
Created by ian on 3/22/2023 in #support-community
Input Validation (with Zod)?
What's the recommended way to do input validation?
2 replies