deen
deen
CCConvex Community
Created by David Alonso on 12/14/2024 in #support-community
Connect to multiple projects from the same nextjs app
You should definitely have these in seperate packages. An easier option when experimenting could to use the Typescript API generator, with a seperate "convex-b" repo, and just copy the generated code across. https://stack.convex.dev/multiple-repos
33 replies
CCConvex Community
Created by David Alonso on 12/14/2024 in #support-community
Connect to multiple projects from the same nextjs app
I talked about this a bit here https://discord.com/channels/1019350475847499849/1312965703690620968 I'm yet to try multi-provider React apps, but I'd lean towards blindly trusting it will just work because the devs are good 😇 I'd be really wary about nesting the providers like that thought, it could be a painful debug if things ever start to get weird - especially with auth involved. If one convex is more of a side-piece to your "main" one - you could try using the "basic" client, or even just one-off requests with the http client. Kinda like a typed fetch... throw in some useEffects, context providers - just like the good old days. Hell you could even add Redux. could be fun!
33 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
After starting a new project with "vanilla" convex, I've spent much of my time experimenting with different patterns for working with my data (instead of actually making the app) - I fully expected to make heavy use of custom ctxes, but found myself instead naturally moving towards this approach. There could a middle ground - I think the current process of defining custom functions is kinda confusing and feels a bit too "magic". Maybe something more structured and formal could ease the cognitive burden - some fancy classes with descriptive names, custom types the user defines that you can see in your ctx after, formalized custom function chaining etc. Maybe even something your convex folders starts out with, in a basic form. It wasn't until after tackling and eventually taming this (needing a handful of attempts, over the course of a few months), that it clicked for me: https://labs.convex.dev/convex-ents/schema/rules#apply-rules It's actually fairly straightforward, but it just looks ugly and weird as hell 😁
22 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
Broadly, this a similar strategy to the custom delete function I suggested - shimming a function of your own into the process, so that you can observe or redirect the flow. Once you get hang of it - it's usually just a few functions to write between you and your goal (like anything else in convex), and then it's not hard to do it in such a way that you barely even notice it's there.
22 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
There isn't a straightforward way of getting the schema definitions back once you've defined them - visible to the naked eye at least. But you already have this information, since you most likely wrote it by hand - you just need to adjust the way you define it, so you can use for whatever you like.
const tableDefinitions = {
regions: defineTable({
name: v.string(),
size: v.number(),
}),
offices: defineTable({
name: v.string(),
address: v.string(),
regionId: v.id('region')
}),
}

const schema = defineSchema(
tableDefinitions,
)

export default schema

export const tableNames = Object.keys(tableDefinitions)
const tableDefinitions = {
regions: defineTable({
name: v.string(),
size: v.number(),
}),
offices: defineTable({
name: v.string(),
address: v.string(),
regionId: v.id('region')
}),
}

const schema = defineSchema(
tableDefinitions,
)

export default schema

export const tableNames = Object.keys(tableDefinitions)
This gives you all of your table names, which you could work with, but you can do better if you pop the fields object out of each table into a variable - then you have the table names with field names. A clever definition pattern could allow you to get every table and field name with a single Object.keys or Object.entries read, exporting the data for your use - and if set up cleanly, you won't even notice it's there. Then you could nominate regionId as a field of interest in your helper function, loop through the table names which have it, query their index, etc. - however works best for your use case. You wouldn't want to run this search as part of just any basic query for regions data in your app, but if it's for a special occasion, like trying to delete a region - then I think that's fine.
22 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
I was using ents as an example of an implementation of delete "guard" functionality (and anticipating the general vibe of Tom's answer) - it's a lot simpler than it sounds. If this check would only happen occasionally, and the regionId fields were indexed (helpfully with a common name), you could enumerate your schema for any tables that have that field, and query for a matching id. I did something similar to look for orphaned _storageIds in an automated fashion - though in my case it was to delete them, but you could just as easily report their existence to the function caller.
22 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
Or you could just mirror the regions data into a second "REGIONS_BACKUP_DO_NOT_DELETE" table and call it a day. The other option is cooler though 😆
22 replies
CCConvex Community
Created by Clever Tagline on 12/13/2024 in #support-community
Request: Is a document is referenced anywhere else?
convex-ents lets you set a table to use soft deletion as part of the schema. When you delete something, it actually just adds a deletionTime field to the document, and that's it. It does this using a few mechanisms, but all of them are just functions in your convex app. With custom functions you can make any dream a reality. The key is to ONLY use your custom functions, all the time, no matter what you're doing. Create them in functions.ts, and import from there. You can just export them as query and mutation, importing the base convex functions with an alias. If you really need to, you can create an eslint rule that prevents you from using the vanilla functions. But once you really get into them, you'll never want to use anything else. Start from this example https://stack.convex.dev/custom-functions#modifying-the-ctx-argument-to-a-server-function-for-user-auth, but we're focused on the mutation function in your case. It's wrapping the db object in an RLS function - you actually want something similar, but only for one table. You can do whatever you like to the ctx object that gets passed in to your functions. Such as: replacing the delete function with your own; intercepting the arguments, checking for the table string 'regions', and throwing an error if you find it. Otherwise just pass through to the regular delete function. That's the first step. if you can do that, implementing your custom relations check on top of it is pretty simple.
22 replies
CCConvex Community
Created by David Alonso on 12/10/2024 in #support-community
Full-text search across fields in different tables
Could the score be exposed? I ended up throwing a few fields into a big text blob because the merged results obviously varied in quality, and I didn't want to run my own search on top of that. These workarounds aren't terrible or anything, but it'd be a nice stopgap until a more advanced solution is available
10 replies
CCConvex Community
Created by cyremur on 11/29/2024 in #support-community
Index on optional nested properties
Yeah I thought you were spoiled too, but looks like you were right! Nice one 😁
5 replies
CCConvex Community
Created by David Alonso on 11/29/2024 in #support-community
Exponential number of indexes required?
Please know I say all this with love! I've never spent so much time with a technology "product" before by choice. The Convex docs are actually really good, and stack is seriously incredible - I have to say, Ian in particular has such an incredible way of explaining a complex topic in a way that feels like it's personally tailored to my brain. I've feel like learned so much that I can apply anywhere - working with the Convex primitives makes navigating these interesting and challenging choices so much more manageable and ... fun? It's all kinda been like a delicious and addictive database onion to me. Something in the nearer term that may be good bang for buck is adding some sort of "intermediate" level example/tutorial that's actually a part of the docs. I find myself jumping to these sections anywhere I encounter them pretty quickly - for me it's really valuable to see the pieces working together in context, even if I don't fully understand them yet. Much less hand-holdy than the Get Started tutorial, more like a clean implementation of a slightly more complex system, demonstrating some of these more advanced concepts working together. Even just seeing single line comments like // we define our validator here separately so we can infer the types for our helper functions can be such a powerful learning multiplier, that makes non-obvious techniques feel natural.
46 replies
CCConvex Community
Created by Tiago Freitas on 11/29/2024 in #support-community
Convex migrations in self-hosted
https://stack.convex.dev/automerge-and-convex Ian's exploration with Automerge doesn't seem to have this issue, according to the Automerge docs, and I doubt convex's own implementation will because they're both using IndexedDB. The WASM stuff is cool but I would be embarrassed to explain to a non-technical client why this doesn't work. Seeing changes reflected almost instantly in side-by-side tabs is still new to most people in my experience - their "delight" moment is really powerful. I also have an end user of my hobby app that uses it on his original iPhone SE, which I doubt will ever support this. Him letting me know whenever something breaks has helped me stay humble - I don't want to exclude people on older devices (within reason). It's never been convex at fault when this has happened.
14 replies
CCConvex Community
Created by itslekan on 11/30/2024 in #support-community
nextjs handling server-side errors in error page
It's a great option as long as your needs aren't too complex - you can't change the query args, and it doesn't work with paginated queries. You'll need to use fetchQuery for those. I hadn't used this set up in a while so I made a little demo in my app to check it. It looked like the data object had been moved in the message by Next. Maybe you could check for an instanceof ConvexError that lacks a data prop - in that case you could try to JSON.parse the data out of the message. Not sure how reliable that would be, but it's something you could try if you needed a fetchQuery. But dealing with it directly in a server component much more reliable, in my opinion.
6 replies
CCConvex Community
Created by bednaz on 12/2/2024 in #support-community
Use Multi Convex projects
Yeah that's why I use Clerk. I'm not sure how it differs with Native. But I would guess any challenge with making this work would be from the Clerk side. Good luck!
8 replies
CCConvex Community
Created by Tiago Freitas on 11/29/2024 in #support-community
Convex migrations in self-hosted
No description
14 replies
CCConvex Community
Created by Tiago Freitas on 11/29/2024 in #support-community
Convex migrations in self-hosted
I'm not trying to convince you of anything. I'm not a Convex staff member - they're probably not going to point out possible pain points for you like I have. I suggested giving it a basic demo because you'll answer your own questions way faster than waiting for someone to compare it PowerSync for you, and try to sell you on the idea. Especially on the self-hosting on your client's servers front. I'm not going to write up a big analysis for someone whose requirements and expectations aren't clear to me - whatever "red flags" you get from that are up to you. For instance, this is the first time you've mentioned conflict resolution being a concern. Conflicts are whatever you decide they are - Convex doesn't maintain local copies of the database on clients. It's more like using Tanstack Query from the front end, but queries are always live and update automatically based on any underlying data that has changed. Your clients should have the same view of the data, which can inform their mutations. If multiplayer mutations on the same data is a primary focus of your app, then you will need to enforce whatever rules that might apply yourself - otherwise, the last write wins. I'd never heard of PowerSync before you mentioned it, so I can't give you a direct comparison. But the db-backend-client chain works seamlessly together, it almost feels like you're working directly with the db on the client. I don't know how to express it any better than that.
14 replies
CCConvex Community
Created by Tiago Freitas on 11/29/2024 in #support-community
Convex migrations in self-hosted
Reading "and huge advantage in having data in an SQL db" is what made me decide to comment. Convex is not SQL, nor is it "NoSQL" because you can have a schema and relations. Your backend and database are essentially the same thing - your Typescript query code both selects the data you need and prepares it for the consumer. For me, that's massive plus - but based on the requirements and legacy app you've mentioned, maybe it's not for you. The PowerSync docs seem like they're primarily about syncing a local SQL database with a remote one. Whereas the Convex docs are more about how to structure your data and backend to deliver the features you want. The concerns and approach are very different. The self-hosted Convex backend doesn't have the dashboard, plus a bunch of the other tooling that make managing your data easy. The readme here https://github.com/get-convex/convex-backend gives a good rundown on the challenges involved - with this be workable with your strict self-hosted requirements? This is a good rundown on the benefits of Convex, thought could perhaps be considered "biased": https://stack.convex.dev/convex-the-database-that-made-me-switch-careers I can't tell you if this is what's right for you, only you can. I don't think you can make an informed choice without experiencing it yourself - the choice should be obvious then.
14 replies
CCConvex Community
Created by David Alonso on 11/29/2024 in #support-community
Exponential number of indexes required?
Yeah, this is essentially what I suggested earlier. It requires having read a few different stack posts, and the lightbulb moment to combine them for this purpose, and probably just a bunch of Convex experience. I don't know exactly why (maybe because it's so novel), but it didn't sink in for me for quite a while that, when I'm using Convex, it's really like just coding my own server in Typescript (mainly). Breaking out of the "on rails" query/mutation/action pattern feels wrong and annoying at first (args types), but once you finally "get it", it's like seeing the Convex Matrix, and everything becomes so much more achievable. It's maybe not as obvious as the team thinks. I wonder how many people never make that leap. Pagination in the docs is presented mainly as a frontend feature for React, with a small example at the end for use with something like Vite. But it's actually required for working with your own data once you get to an intermediate level, and it wasn't until after many re-reads of the Great Stack Post of All Time, "Stateful Online Migrations using Mutations", that this clicked for me. Also, be careful because Paginated Queries are a beta feature 😉 This definitely isn't Day 1 of Convex stuff, so I'm not exactly sure how to present it, but I think if you look at the most common questions that keep coming up here, making this leap is an issue. (see: "helper functions")
46 replies
CCConvex Community
Created by David Alonso on 11/29/2024 in #support-community
Exponential number of indexes required?
I would love to hear if the team has any more specific advice on this problem in general - how to approach filtering documents based on many possible fields, that may or may not be specified. Obviously, tradeoffs must be made somewhere, it depends on your data etc., but this is an extremely common pattern found in pretty much any software bigger than a toy app. Other databases generally encapsulate many of these decisions from you, for better or worse. Convex asks you to think about and make these choices explicitly - but there is little guidance and plenty of confusion about how to approach this. I don't think the Convex story is very good here. How would you implement something like the Linear issues filter feature? Or how would the Convex team think about implementing a comprehensive search/filter system like this for say, Dropbox for instance? Any relevant wisdom would be greatly appreciated.
46 replies
CCConvex Community
Created by bednaz on 12/2/2024 in #support-community
Use Multi Convex projects
I've transferred/transformed data between two different convex apps, and the dev/prod env of the same app, using a simple typescript module run with bun. It works great - they don't do silly any global that would interfere with each other. I assume the browser is the same, but I haven't tried it. I think any complexity will come down to however you structure your implementation, and the Clerk side. I don't know if this what you're aiming for, but could another approach making your auth service backend only, and your app convex reaches out to that? Getting a tokenIdentifer on the convex side is simple - you just need the auth.config.ts and env var (I don't even think you need to install anything?). The app convex can reach out to your auth service with the id to find out what to do with it directly, rather than your front end having to be concerned about the dance between two convexes. Clerk is particular about domains, but I think you can just point its webhooks anywhere. I've never used a Clerk instance with more than one domain - not sure if you plan on have multiple Clerks or trying to share one. Long story short, yeah you can use multiple convex clients :convex: . I'd be interested in hearing about what you come up with.
8 replies