Hey all, does anyone know if there is a Table helper equivalent for convex ENTs?
Trying to see if it's possible to collocate validators with schema definitions using the ENTs abstraction.
For example, I am currently using the
defineEnts
method to define a table in my schema:
And I am exporting a separate obj in order to infer argument validation for the corresponding create
mutation:
Just wondering if there is a way to declare the validator once and feed it into the schema with the ENT-way of doing things. As outlined in the best practices of not redefining the shape in vanilla convex:
19 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I don't think there is a way to do this, otherwise i should rewrite a lot of my schema. I just define most of it the old way. The only issue would be when using unique: true
I do vaugely recall this being talked about somewhere here in discord...
I ended up minimizing my use of .field definitions due to losing this convenience, especially if you're using return type validators. You can still use regular index definitions, and I only use field for the fancy stuff like unique and default, or for fields that I don't usually want in public validators anyway (eg. updatedAtTime).
I'd still definitely recommend colocating your ent definitions with related validators/functions - if you make good use of the convex helper utils, you can vastly cut down on repetitive code, and easily keep your validators in sync if you change your schema. My
convex/schema.ts
file has very few actualy ent defininitions in it - they're all imported from their domain areas across the app.this all makes sense - I like your approach. Thanks for clarifying and for the example! Appreciate it.
In my case i extended convex-ents by adding an updateField function in the entitydefinition class that does not throw an exception when a field already exists , using this in place of field, i can pass all fields into the Table helper call , and still define attributes like unique,defualt and index the way i do currently and it works without issues . Am going to do a PR to convex-ents maybe they accept it . for now am using convex-ents off of my github branch
Nice, you probably have a good chance for PR, i look forward to it 🙂
Cool. I will push it
Yeah, probably a good idea to drop a link to it in #convex-ents also
in Action
Hmm, i think the only friction would be having to maintain the string() part in two places, maybe something like .fieldProps('teamname', { unique: true }) makes it a bit more clear? or addFieldProps/features.. assuming it is better language, i don't exactly see a label in the docs for that data within { }
I can modify that . I dont get the line "i don't exactly see a label in the docs for that data within { }" . are you referring to the PR ?
I was looking in the ents docs to see if { default,index,unique } has a name like properties etc, but its probably only referenced in code
if you look at the type definition for field (and updateField which is currently thesame), option (the object {}) has a type with 3 optional properties : default,unique and index
lol, yeah duh.. options.. maybe just .options('fieldName', { options })
or .fieldOptions ?
Yeah, that's probably best. Ill be happy to use it however 🙃 - i'm already doing a lot of like what dean is doing, but still got many more tables to update.
It would definitely make rewriting ai-town to ents much faster...😅
yeah it would.
PR is in and updated
OK, am running into an issue at runtime , where the fieldPath for fieldOptions are missing causing queries to fail. Am looking at that