Class BrightBaseCRUD<TableRecord, CreateOptions>

Class representing CRUD operations for a Supabase table.

Type Parameters

  • TableRecord extends {
        [key: string]: unknown;
    }

    The type of table record.

  • CreateOptions extends {
        OmitOnCreate: keyof TableRecord;
        OptionalOnCreate: keyof TableRecord;
    } = {
        OmitOnCreate: "id" | "created_at";
        OptionalOnCreate: "";
    }

    The configuration object for create operations.

Constructors

Properties

Methods

Constructors

Properties

name: string

Methods

  • Deletes a record from the table by its ID.

    Parameters

    Returns Promise<null>

    The deleted record.

    If there is an error during deletion.

    userTable.delete('id_of_record').then((users) => console.log(users)).catch(err => wetToast(err.message, { icon: '❌' })
    
  • Reads records from the table based on the provided filters and options.

    Parameters

    • Optionalfilters: Partial<{
          [key in string | number | symbol]: TableRecord[key]
      }> = {}

      The filters to apply to the query.

    • Optionaloptions: {
          limit?: number;
          offset?: number;
          order?: {
              ascending: boolean;
              by: string;
          };
      } = {}

      The options for the query, such as limit and order.

      • Optionallimit?: number
      • Optionaloffset?: number
      • Optionalorder?: {
            ascending: boolean;
            by: string;
        }
        • ascending: boolean
        • by: string

    Returns Promise<TableRecord[]>

    The fetched records.

    If there is an error during record retrieval or no data is found.

    userTable.read({ name: 'John Doe' }, { limit: 10 }).then((users) => console.log(users)).catch(err => wetToast(err.message, { icon: '❌' })
    
  • Updates a record in the table by its ID.

    Parameters

    • id: TableRecord["id"]

      The ID of the record to update.

    • updates: Partial<TableRecord>

      The updates to apply to the record.

    Returns Promise<TableRecord[]>

    The updated records.

    If there is an error during the update.

    userTable.update('id_of_record', { name: 'Jane Doe' }).then((users) => console.log(users)).catch(err => wetToast(err.message, { icon: '❌' })