import type { FieldTypeFromFieldPath, TableNamesInDataModel, GenericDataModel, GenericDatabaseReader, DocumentByName, SystemTableNames, SystemDataModel, NamedIndex, NamedTableInfo, IndexNames, FieldPaths } from "convex/server"; import type { GenericId } from "convex/values"; /** * Gets a document by its ID. Throws if not found. * * @param ctx The database reader to use to get the document. * @param table The table name. * @param id The id of the document to get. * @returns The document with the given ID. */ export declare function getOrThrow>(ctx: { db: GenericDatabaseReader; }, table: Table, id: GenericId>): Promise>; /** * Gets a document by its ID. Throws if not found. * @param ctx The database reader to use to get the document. * @param id The id of the document to get. * @returns The document with the given ID. */ export declare function getOrThrow>(ctx: { db: GenericDatabaseReader; }, id: GenericId): Promise>; /** * getAll returns a list of Documents (or null) for the `Id`s passed in. * * Nulls are returned for documents not found. * @param db A DatabaseReader, usually passed from a mutation or query ctx. * @param table The table name. * @param ids An list (or other iterable) of Ids pointing to a table. * @returns The Documents referenced by the Ids, in order. `null` if not found. */ export declare function getAll>(db: GenericDatabaseReader, table: TableName, ids: Iterable>> | Promise>>>): Promise<(DocumentByName | null)[]>; /** * getAll returns a list of Documents (or null) for the `Id`s passed in. * * Nulls are returned for documents not found. * @param db A DatabaseReader, usually passed from a mutation or query ctx. * @param ids An list (or other iterable) of Ids pointing to a table. * @returns The Documents referenced by the Ids, in order. `null` if not found. */ export declare function getAll>(db: GenericDatabaseReader, ids: Iterable> | Promise>>): Promise<(DocumentByName | null)[]>; /** * getAllOrThrow returns a list of Documents for the `Id`s passed in. * * It throws if any documents are not found (null). * @param db A DatabaseReader, usually passed from a mutation or query ctx. * @param table The table name. * @param ids An list (or other iterable) of Ids pointing to a table. * @returns The Documents referenced by the Ids, in order. */ export declare function getAllOrThrow>(db: GenericDatabaseReader, table: TableName, ids: Iterable>> | Promise>>>): Promise[]>; /** * getAllOrThrow returns a list of Documents for the `Id`s passed in. * * It throws if any documents are not found (null). * @param db A DatabaseReader, usually passed from a mutation or query ctx. * @param ids An list (or other iterable) of Ids pointing to a table. * @returns The Documents referenced by the Ids, in order. */ export declare function getAllOrThrow>(db: GenericDatabaseReader, ids: Iterable> | Promise>>): Promise[]>; type UserIndexes> = Exclude>, "by_creation_time"> & string; type TablesWithLookups = { [T in TableNamesInDataModel]: UserIndexes extends never ? never : T; }[TableNamesInDataModel]; type FirstIndexField, IndexName extends IndexNames>> = NamedIndex, IndexName>[0]; type TypeOfFirstIndexField, IndexName extends IndexNames>> = IndexName extends IndexNames> ? FieldTypeFromFieldPath, NamedIndex, IndexName>[0]> : never; type LookupFieldPaths> = { [IndexName in UserIndexes]: FirstIndexField; }[UserIndexes]; type FieldIfDoesntMatchIndex, IndexName extends UserIndexes> = FirstIndexField extends IndexName ? IndexName extends `by_${infer _}` ? never : [FirstIndexField?] : `by_${FirstIndexField}` extends IndexName ? [FirstIndexField?] : [FirstIndexField]; /** * Get a document matching the given value for a specified field. * * `null` if not found. * Useful for fetching a document with a one-to-one relationship via backref. * Requires the table to have an index on the field named the same as the field. * e.g. `defineTable({ fieldA: v.string() }).index("fieldA", ["fieldA"])` * * Getting 'string' is not assignable to parameter of type 'never'? * Make sure your index is named after your field. * * @param db DatabaseReader, passed in from the function ctx * @param table The table to fetch the target document from. * @param index The index on that table to look up the specified value by. * @param value The value to look up the document by, often an ID. * @param field The field on that table that should match the specified value. * Optional if the index is named after the field. * @returns The document matching the value, or null if none found. */ export declare function getOneFrom, IndexName extends UserIndexes>(db: GenericDatabaseReader, table: TableName, index: IndexName, value: TypeOfFirstIndexField, ...fieldArg: FieldIfDoesntMatchIndex): Promise | null>; /** * Get a document matching the given value for a specified field. * * Throws if not found. * Useful for fetching a document with a one-to-one relationship via backref. * Requires the table to have an index on the field named the same as the field. * e.g. `defineTable({ fieldA: v.string() }).index("fieldA", ["fieldA"])` * * Getting 'string' is not assignable to parameter of type 'never'? * Make sure your index is named after your field. * * @param db DatabaseReader, passed in from the function ctx * @param table The table to fetch the target document from. * @param index The index on that table to look up the specified value by. * @param value The value to look up the document by, often an ID. * @param field The field on that table that should match the specified value. * Optional if the index is named after the field. * @returns The document matching the value. Throws if not found. */ export declare function getOneFromOrThrow, IndexName extends UserIndexes>(db: GenericDatabaseReader, table: TableName, index: IndexName, value: TypeOfFirstIndexField, ...fieldArg: FieldIfDoesntMatchIndex): Promise>; /** * Get a list of documents matching the given value for a specified field. * * Useful for fetching many documents related to a given value via backrefs. * Requires the table to have an index on the field named the same as the field. * e.g. `defineTable({ fieldA: v.string() }).index("fieldA", ["fieldA"])` * * Getting 'string' is not assignable to parameter of type 'never'? * Make sure your index is named after your field. * * @param db DatabaseReader, passed in from the function ctx * @param table The table to fetch the target document from. * @param index The index on that table to look up the specified value by. * @param value The value to look up the document by, often an ID. * @param field The field on that table that should match the specified value. * Optional if the index is named after the field. * @returns The documents matching the value, if any. */ export declare function getManyFrom, IndexName extends UserIndexes>(db: GenericDatabaseReader, table: TableName, index: IndexName, value: TypeOfFirstIndexField, ...fieldArg: FieldIfDoesntMatchIndex): Promise[]>; type IdFilePaths, TableName extends TableNamesInDataModel | SystemTableNames> = { [FieldName in FieldPaths>]: FieldTypeFromFieldPath, FieldName> extends GenericId ? FieldName extends "_id" ? never : FieldName : never; }[FieldPaths>]; type LookupAndIdFilePaths> = { [FieldPath in IdFilePaths | SystemTableNames>]: LookupFieldPaths extends FieldPath ? never : true; }[IdFilePaths | SystemTableNames>]; type JoinTables = { [TableName in TablesWithLookups]: LookupAndIdFilePaths extends never ? never : TableName; }[TablesWithLookups]; type DocumentByNameOrSystem | SystemTableNames> = TableName extends TableNamesInDataModel ? DocumentByName : TableName extends SystemTableNames ? SystemDataModel[TableName]["document"] : never; /** * Get related documents by using a join table. * * Any missing documents referenced by the join table will be null. * It will find all join table entries matching a value, then look up all the * documents pointed to by the join table entries. Useful for many-to-many * relationships. * * Requires your join table to have an index on the fromField named the same as * the fromField, and another field that is an Id type. * e.g. `defineTable({ a: v.string(), b: v.id("users") }).index("a", ["a"])` * * Getting 'string' is not assignable to parameter of type 'never'? * Make sure your index is named after your field. * * @param db DatabaseReader, passed in from the function ctx * @param table The table to fetch the target document from. * @param toField The ID field on the table pointing at target documents. * @param index The index on the join table to look up the specified value by. * @param value The value to look up the documents in join table by. * @param field The field on the join table to match the specified value. * Optional if the index is named after the field. * @returns The documents targeted by matching documents in the table, if any. */ export declare function getManyVia, ToField extends IdFilePaths | SystemTableNames>, IndexName extends UserIndexes, TargetTableName extends FieldTypeFromFieldPath, ToField> extends GenericId ? TargetTableName : never>(db: GenericDatabaseReader, table: JoinTableName, toField: ToField, index: IndexName, value: TypeOfFirstIndexField, ...fieldArg: FieldIfDoesntMatchIndex): Promise<(DocumentByNameOrSystem | null)[]>; /** * Get related documents by using a join table. * * Throws an error if any documents referenced by the join table are missing. * It will find all join table entries matching a value, then look up all the * documents pointed to by the join table entries. Useful for many-to-many * relationships. * * Requires your join table to have an index on the fromField named the same as * the fromField, and another field that is an Id type. * e.g. `defineTable({ a: v.string(), b: v.id("users") }).index("a", ["a"])` * * Getting 'string' is not assignable to parameter of type 'never'? * Make sure your index is named after your field. * * @param db DatabaseReader, passed in from the function ctx * @param table The table to fetch the target document from. * @param toField The ID field on the table pointing at target documents. * @param index The index on the join table to look up the specified value by. * @param value The value to look up the documents in join table by. * @param field The field on the join table to match the specified value. * Optional if the index is named after the field. * @returns The documents targeted by matching documents in the table, if any. */ export declare function getManyViaOrThrow, ToField extends IdFilePaths | SystemTableNames>, IndexName extends UserIndexes, TargetTableName extends FieldTypeFromFieldPath, ToField> extends GenericId ? TargetTableName : never>(db: GenericDatabaseReader, table: JoinTableName, toField: ToField, index: IndexName, value: TypeOfFirstIndexField, ...fieldArg: FieldIfDoesntMatchIndex): Promise[]>; /** * This prevents TypeScript from inferring that the generic `TableName` type is * a union type when `table` and `id` disagree. */ type NonUnion = T extends never ? never : T; export {}; //# sourceMappingURL=relationships.d.ts.map