Skip to content

Commit

Permalink
Revert "allow "_id" filters in index queries (#23979)" (#24165)
Browse files Browse the repository at this point in the history
This reverts commit 779e62021d30cd9d04386e141f657940eeb2b69c.

filters on `_id` don't work in virtual tables

GitOrigin-RevId: 0e81147a337af0cbb78fdfc67e7960e480b0b6e5
  • Loading branch information
ldanilek authored and Convex, Inc. committed Apr 1, 2024
1 parent 2ecd788 commit b9bcecb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export type {
WithoutSystemFields,
WithOptionalSystemFields,
SystemIndexes,
IndexTiebreakerFields,
IndexTiebreakerField,
} from "./system_fields.js";
export { httpRouter, HttpRouter, ROUTABLE_HTTP_METHODS } from "./router.js";
export type { RoutableMethod } from "./router.js";
Expand Down
14 changes: 4 additions & 10 deletions src/server/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,11 @@ describe("DataModelFromSchemaDefinition", () => {
| "property1"
| "property2";
type ExpectedIndexes = {
by_property1: ["property1", "_creationTime", "_id"];
by_property1_property2: [
"property1",
"property2",
"_creationTime",
"_id",
];
by_property1: ["property1", "_creationTime"];
by_property1_property2: ["property1", "property2", "_creationTime"];

// System indexes
by_creation_time: ["_creationTime", "_id"];
by_id: ["_id"];
// System index
by_creation_time: ["_creationTime"];
};
type ExpectedDataModel = {
table: {
Expand Down
4 changes: 2 additions & 2 deletions src/server/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
} from "../server/data_model.js";
import {
IdField,
IndexTiebreakerFields,
IndexTiebreakerField,
SystemFields,
SystemIndexes,
} from "../server/system_fields.js";
Expand Down Expand Up @@ -200,7 +200,7 @@ export class TableDefinition<
Indexes &
Record<
IndexName,
[FirstFieldPath, ...RestFieldPaths, ...IndexTiebreakerFields]
[FirstFieldPath, ...RestFieldPaths, IndexTiebreakerField]
>
>,
SearchIndexes,
Expand Down
13 changes: 7 additions & 6 deletions src/server/system_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ export type WithOptionalSystemFields<Document extends GenericDocument> = Expand<
* @public
*/
export type SystemIndexes = {
// Note `db.get(id)` is simpler and equivalent to a query on `by_id`.
// Unless the query is being built dynamically, or doing manual pagination.
by_id: ["_id"];
// We have a system index `by_id` but developers should never have a use
// for querying it (`db.get(id)` is always simpler).
// by_id: ["_id"];

by_creation_time: ["_creationTime", "_id"];
by_creation_time: ["_creationTime"];
};

/**
* Convex automatically appends "_creationTime" and "_id" to the end of every index to break ties if all other fields are identical.
* Convex automatically appends "_creationTime" to the end of every index to
* break ties if all of the other fields are identical.
* @public
*/
export type IndexTiebreakerFields = ["_creationTime", "_id"];
export type IndexTiebreakerField = "_creationTime";

0 comments on commit b9bcecb

Please sign in to comment.