collectionConfigToVexSchema
collectionConfigToVexSchema(
props):string
Defined in: packages/core/src/collections/validator.ts:104
Converts a resolved CollectionConfig to a Convex defineTable(...) source string.
Iterates the collection’s fields, builds each field’s Convex validator via
adminFieldToValidator, and appends index chains:
.index()for fields with an explicitfield.indexproperty.index("by_<fieldKey>", ["<fieldKey>"])auto-generated for every relationship field.searchIndex()for text fields withfield.searchIndexconfigured.searchIndex("search_<useAsTitle>", { searchField: "<useAsTitle>", filterFields: [] })auto-generated when another collection has a relationship pointing HERE anduseAsTitleis not a Convex system field (_id,_creationTime), provided no manually configured search index already has that name.
Parameters
Section titled “Parameters”Input props.
collection
Section titled “collection”The resolved collection definition to convert.
config
Section titled “config”The full resolved VexCMS config, needed for cross-collection relationship detection.
Returns
Section titled “Returns”string
A TypeScript source string declaring the Convex table.
Example
Section titled “Example”const posts = defineCollection({ slug: "posts", fields: { author: relationship({ collection: "authors", required: true }) },});collectionConfigToVexSchema({ collection: posts, config });// → 'export const posts = defineTable({...})\n\t.index("by_author", ["author"])'
@see {@link generateVexSchema} for the full-file generator that wraps this function@see {@link getIncomingRelationships} for the cross-collection helper