Interface representing a generic data connector for performing CRUD operations and custom queries.

interface Connector<T> {
    create(collectionName: string, data: T): Promise<T>;
    delete(collectionName: string, id: string | number): Promise<boolean>;
    findAll(
        collectionName: string,
        query: string,
        bindings: any[],
    ): Promise<T[]>;
    findOne(collectionName: string, query: string, bindings: any[]): Promise<T>;
    getAll(collectionName: string): Promise<T[]>;
    getById(collectionName: string, id: string | number): Promise<T>;
    update(collectionName: string, data: T): Promise<T>;
}

Type Parameters

  • T

    The type of the data being managed by the connector.

Implemented by

Methods

  • Creates a new document within the specified collection using the provided data.

    Parameters

    • collectionName: string

      The name of the collection where the document will be created.

    • data: T

      The data object representing the document to be created.

    Returns Promise<T>

    A promise that resolves to the created document.

  • Deletes a document or record from the specified collection using its unique identifier.

    Parameters

    • collectionName: string

      The name of the collection or table from which the item is to be deleted.

    • id: string | number

      The unique identifier of the document or record to be deleted.

    Returns Promise<boolean>

    A promise that resolves to true if the deletion is successful, otherwise false.

  • Retrieves all records from the specified collection that match the given query.

    Parameters

    • collectionName: string

      The name of the collection to query.

    • query: string

      The SQL or query string to execute.

    • bindings: any[]

      Optional bindings to parameterize the query.

    Returns Promise<T[]>

    A promise that resolves to an array of matching records.

  • Finds a single record in the specified collection that matches the given query and bindings.

    Parameters

    • collectionName: string

      The name of the collection to search in.

    • query: string

      The query string to filter the records.

    • bindings: any[]

      Optional additional parameters to bind to the query.

    Returns Promise<T>

    A promise that resolves with the first record matching the query, or null if no match is found.

  • Retrieves all documents from the specified collection.

    Parameters

    • collectionName: string

      The name of the collection to retrieve documents from.

    Returns Promise<T[]>

    A promise that resolves to an array of documents from the collection.

  • Retrieves an item by its unique identifier from the specified collection.

    Parameters

    • collectionName: string

      The name of the collection from which to fetch the item.

    • id: string | number

      The unique identifier of the item to retrieve. Can be a number or a string.

    Returns Promise<T>

    A promise that resolves to the item of type T if found, or rejects with an error.

  • Updates a record in the specified collection with the provided data.

    Parameters

    • collectionName: string

      The name of the collection to update.

    • data: T

      The data to update the record with.

    Returns Promise<T>

    A promise that resolves to the updated record.