Skip to content

Commit

Permalink
Add non-speciifc ensureIndex
Browse files Browse the repository at this point in the history
Fixes #778.
  • Loading branch information
pluma4345 committed Jul 19, 2024
1 parent efb7355 commit 4f675f9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This driver uses semantic versioning:

### Changed

- Split the Collection type parameter into result and input types [#807](https://github.com/arangodb/arangojs/issues/807)
- Split the Collection type parameter into result and input types ([#807](https://github.com/arangodb/arangojs/issues/807))

It is now possible to specify a separate type for the data passed when
creating or modifying documents in addition to the type of the data returned
Expand All @@ -31,6 +31,11 @@ This driver uses semantic versioning:

This option was introduced in 3.12.1 and allows skipping the fast lock round.

- Added non-specific `EnsureIndexOptions` type and `ensureIndex` method
signature ([#778](https://github.com/arangodb/arangojs/issues/778))

This allows creating indexes without narrowing the index type.

## [9.0.0-preview.4] - 2024-06-18

### Added
Expand Down
22 changes: 22 additions & 0 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
TtlIndex,
MdiIndex,
_indexHandle,
EnsureIndexOptions,
} from "./indexes.js";
import { COLLECTION_NOT_FOUND, DOCUMENT_NOT_FOUND } from "./lib/codes.js";

Expand Down Expand Up @@ -2006,6 +2007,27 @@ export interface DocumentCollection<
ensureIndex(
details: EnsureInvertedIndexOptions
): Promise<ArangoApiResponse<InvertedIndex & { isNewlyCreated: boolean }>>;
/**
* Creates an index on the collection if it does not already exist.
*
* @param details - Options for creating the index.
*
* @example
* ```js
* const db = new Database();
* const collection = db.collection("some-collection");
* // Create a unique index for looking up documents by username
* await collection.ensureIndex({
* type: "persistent",
* fields: ["username"],
* name: "unique-usernames",
* unique: true
* });
* ```
*/
ensureIndex(
details: EnsureIndexOptions
): Promise<ArangoApiResponse<Index & { isNewlyCreated: boolean }>>;
/**
* Deletes the index with the given name or `id` from the database.
*
Expand Down
10 changes: 10 additions & 0 deletions src/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,16 @@ export type EnsureInvertedIndexOptions = {
optimizeTopK?: string[];
};

/**
* Options for creating an index.
*/
export type EnsureIndexOptions =
| EnsurePersistentIndexOptions
| EnsureGeoIndexOptions
| EnsureTtlIndexOptions
| EnsureMdiIndexOptions
| EnsureInvertedIndexOptions;

/**
* Shared attributes of all index types.
*/
Expand Down

0 comments on commit 4f675f9

Please sign in to comment.