StarlordS
Convex Community14mo ago
2 replies
Starlord

https://github.com/get-convex/convex-

https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/README.md#validator-utilities

in validator utils i need to define table again to validate parameters. is it possible to use existing from schema?

import { Table } from "convex-helpers/server";
import {
  literals,
  partial,
  deprecated,
  brandedString,
} from "convex-helpers/validators";
import { omit, pick } from "convex-helpers";
import { Infer } from "convex/values";

// Define a validator that requires an Email string type.
export const emailValidator = brandedString("email");
// Define the Email type based on the branded string.
export type Email = Infer<typeof emailValidator>;

export const Account = Table("accounts", {
  balance: nullable(v.bigint()),
  status: literals("active", "inactive"),
  email: emailValidator,

  oldField: deprecated,
});

// convex/schema.ts
export default defineSchema({
  accounts: Account.table.index("status", ["status"]),
  //...
});
Was this page helpful?