File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ This driver uses semantic versioning:
1818
1919### Changed
2020
21- - Split the Collection type parameter into result and input types [ #807 ] ( https://github.com/arangodb/arangojs/issues/807 )
21+ - Split the Collection type parameter into result and input types ( [ #807 ] ( https://github.com/arangodb/arangojs/issues/807 ) )
2222
2323 It is now possible to specify a separate type for the data passed when
2424 creating or modifying documents in addition to the type of the data returned
@@ -31,6 +31,11 @@ This driver uses semantic versioning:
3131
3232 This option was introduced in 3.12.1 and allows skipping the fast lock round.
3333
34+ - Added non-specific ` EnsureIndexOptions ` type and ` ensureIndex ` method
35+ signature ([ #778 ] ( https://github.com/arangodb/arangojs/issues/778 ) )
36+
37+ This allows creating indexes without narrowing the index type.
38+
3439## [ 9.0.0-preview.4] - 2024-06-18
3540
3641### Added
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ import {
4040 TtlIndex ,
4141 MdiIndex ,
4242 _indexHandle ,
43+ EnsureIndexOptions ,
4344} from "./indexes.js" ;
4445import { COLLECTION_NOT_FOUND , DOCUMENT_NOT_FOUND } from "./lib/codes.js" ;
4546
@@ -2006,6 +2007,27 @@ export interface DocumentCollection<
20062007 ensureIndex (
20072008 details : EnsureInvertedIndexOptions
20082009 ) : Promise < ArangoApiResponse < InvertedIndex & { isNewlyCreated : boolean } > > ;
2010+ /**
2011+ * Creates an index on the collection if it does not already exist.
2012+ *
2013+ * @param details - Options for creating the index.
2014+ *
2015+ * @example
2016+ * ```js
2017+ * const db = new Database();
2018+ * const collection = db.collection("some-collection");
2019+ * // Create a unique index for looking up documents by username
2020+ * await collection.ensureIndex({
2021+ * type: "persistent",
2022+ * fields: ["username"],
2023+ * name: "unique-usernames",
2024+ * unique: true
2025+ * });
2026+ * ```
2027+ */
2028+ ensureIndex (
2029+ details : EnsureIndexOptions
2030+ ) : Promise < ArangoApiResponse < Index & { isNewlyCreated : boolean } > > ;
20092031 /**
20102032 * Deletes the index with the given name or `id` from the database.
20112033 *
Original file line number Diff line number Diff line change @@ -518,6 +518,16 @@ export type EnsureInvertedIndexOptions = {
518518 optimizeTopK ?: string [ ] ;
519519} ;
520520
521+ /**
522+ * Options for creating an index.
523+ */
524+ export type EnsureIndexOptions =
525+ | EnsurePersistentIndexOptions
526+ | EnsureGeoIndexOptions
527+ | EnsureTtlIndexOptions
528+ | EnsureMdiIndexOptions
529+ | EnsureInvertedIndexOptions ;
530+
521531/**
522532 * Shared attributes of all index types.
523533 */
You can’t perform that action at this time.
0 commit comments