Documentation
    Preparing search index...

    Class Slice<T>

    An object to aid in constructing Datalynk requests

    Type Parameters

    • T = any
    Index

    Constructors

    • An object to aid in constructing requests

      Type Parameters

      • T = any

      Parameters

      • slice: string | number

        Slice ID to interact with

      • api: Api

        Api to send the requests through

      Returns Slice<T>

    Properties

    alias: {
        (whitelist: string[]): Slice<T>;
        (alias: { [key: string]: string | object }): Slice<T>;
    } = ...

    Whitelist and alias fields. Alias of fields()

    Type declaration

      • (whitelist: string[]): Slice<T>
      • Whitelist fields by passing an array of keys or alias fields by using a map

        Parameters

        • whitelist: string[]

          Either a list of keys to whitelist or a map of keys to rename

        Returns Slice<T>

        const id: {id: number, field1: any}[] = await new Slice<T>(12345)
        .select().fields(['id', 'field1']).exec().keys();
      • (alias: { [key: string]: string | object }): Slice<T>
      • Whitelist fields by passing an array of keys or alias fields by using a map

        Parameters

        • alias: { [key: string]: string | object }

        Returns Slice<T>

        const id: {id: number, field1: any}[] = await new Slice<T>(12345)
        .select().fields(['id', 'field1']).exec().keys();
    const id: {id: number, field2: any}[] = await new Slice<T>(12345)
    .select().alias({id: 'id', field1: 'field2'}).exec().keys();

    List of properties to whitelist and what to rename them to

    debugging?: boolean

    Log response automatically

    unsubscribe?: null | Unsubscribe

    Unsubscribe from changes, undefined if not subscribed

    api: Api

    Accessors

    • get raw(): Partial<{ $pop: undefined | string; [key: string]: any }>

      Get raw API request

      Returns Partial<{ $pop: undefined | string; [key: string]: any }>

    Methods

    • Add an 'AND' condition inside the where argument

      Returns Slice<T>

      const rows: T[] = await new Slice<T>(12345).select()
      .where('field1', '>', 1)
      .and()
      .where({field2: 2, field3: 3})
      .exec().rows();
    • Count the returned rows

      Parameters

      • arg: string | object = 'id'

        Count argument

      Returns Slice<T>

      const count = await new Slice(12345).count()
      .where({field1: 1})
      .exec().count();
    • Output the formed request to the console for inspection

      Parameters

      • enabled: boolean = true

        Enable/Disable console logging

      Returns Slice<T>

    • Set the request type to delete

      Parameters

      • Optionalid: number | number[]

        ID(s) to delete

      Returns Slice<T>

      await new Slice(12345).delete(id).exec();
      
    • Filter rows from slice based on an excel expression

      Parameters

      • formula: string

        Excel formula to use as where clause

      Returns Slice<T>

      const rows: T[] = await new Slice<T>(12345).select()
      .excel('contains({property}, foobar)')
      .exec().rows();
    • Compile the request and send it

      Type Parameters

      • T = any

      Parameters

      Returns Promise<T>

      API response

    • Whitelist fields by passing an array of keys or alias fields by using a map

      Parameters

      • whitelist: string[]

        Either a list of keys to whitelist or a map of keys to rename

      Returns Slice<T>

      const id: {id: number, field1: any}[] = await new Slice<T>(12345)
      .select().fields(['id', 'field1']).exec().keys();
    • Whitelist fields by passing an array of keys or alias fields by using a map

      Parameters

      • alias: { [key: string]: string | object }

      Returns Slice<T>

      const id: {id: number, field1: any}[] = await new Slice<T>(12345)
      .select().fields(['id', 'field1']).exec().keys();
    • Unwrap response returning the first ID

      Returns Slice<T>

    • Set the request type to insert

      Parameters

      • rows: T | T[]

        Rows to be inserted into the slice

      Returns Slice<T>

      const id: number = await new Slice<T>(12345).insert([
      {field1: 1},
      {field1: 2}
      ]).exec().keys();
    • Limit number of rows returned

      Parameters

      • num: number

        Number of rows to return

      Returns Slice<T>

      const rows: T[] = await new Slice<T>(12345).select().limit(10)
      .exec().rows();
    • Add an 'OR' condition inside the where argument

      Returns Slice<T>

      const rows: T[] = await new Slice<T>(12345).select()
      .where('field1', '>', 1)
      .or()
      .where({field2: 2, field3: 3})
      .or()
      .where(['$gt', ['$field', field4], 4)
      .exec().rows();
    • Order rows by a field

      Parameters

      • field: string

        property name

      • ascending: boolean = true

        Sort in ascending or descending order

      Returns Slice<T>

      const rows: T[] = new Slice<T>(12345).select().order('field1', true) // true = ascending
      .exec().rows();
    • Unwrap response, returning the field

      Parameters

      • field: null | string

        Colon seperated path: rows:0

      Returns Slice<T>

    • Unwrap response returning the first row

      Returns Slice<T>

    • Unwrap response returning the rows

      Returns Slice<T>

    • Set the request type to select

      Parameters

      • Optionalid: number | number[]

        ID(s) to select, leaving blank will return all rows

      Returns Slice<T>

      const rows: T[] = new Slice<T>(12345).select().exec().rows();
      const row: T = new Slice<T>(12345).select(id).exec().row();
    • Synchronize cache with server

      Parameters

      • on: boolean = true

        Enable/disable events

      Returns undefined | BehaviorSubject<T[]>

      Cache which can be subscribed to

      const slice: Slice = new Slice<T>(Slices.Contact);
      slice.sync().subscribe((rows: T[]) => {});
    • Set the request type to update

      Parameters

      • rows: T | T[]

        Rows to be updated, each row must have an ID

      Returns Slice<T>

      const ids: number[] = await new Slice<Type>(12345).update([
      {id: 1, field1: 1},
      {id: 2, field1: 1}
      ]).exec().keys();
    • Add where condition to request

      Parameters

      • field: string | object

        property to compare or a map of equality comparisons

      • Optionaloperator: string

        Operation to compare with. Accepts JS operators (>=, ==, !=, ...) as well as datalynk styax ($gte, $eq, $is, $not, ...)

      • Optionalvalue: any

        value to compare against

      Returns Slice<T>

      const rows: T[] = await new Slice<T>(12345).select()
      .where('field1', '>', 1)
      .where({field2: 2, field3: 3}) // Automatic AND
      .or()
      .where(['$gt', ['$field', field4], 4)
      .exec().rows();