Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • ModelPredicateCreator

Index

Methods

Static createForPk

  • createForPk<T>(modelDefinition: SchemaModel, model: T): object & object
  • using the PK values from the given model (which can be a partial of T Creates a predicate that matches an instance described by modelDefinition that contains only PK field values.)

    Type parameters

    Parameters

    • modelDefinition: SchemaModel

      The model definition to create a predicate for.

    • model: T

      The model instance to extract value equalities from.

    Returns object & object

Static createFromAST

  • Accepts a GraphQL style filter predicate tree and transforms it into a predicate that storage adapters understand. Example input:

    {
        and: [
            { name: { eq: "Bob Jones" } },
            { age: { between: [32, 64] } },
            { not: {
                or: [
                    { favoriteFood: { eq: 'pizza' } },
                    { favoriteFood: { eq: 'tacos' } },
                ]
            }}
        ]
    }

    Type parameters

    Parameters

    • modelDefinition: SchemaModel

      The model that the AST/predicate must be compatible with.

    • ast: any

      The graphQL style AST that should specify conditions for modelDefinition.

    Returns ModelPredicate<T>

Static createFromFlatEqualities

  • createFromFlatEqualities<T>(modelDefinition: SchemaModel, flatEqualities: Record<string, any>): object & object
  • Searches a Model table for records matching the given equalities object.

    This only matches against fields given in the equalities object. No other fields are tested by the predicate.

    Type parameters

    Parameters

    • modelDefinition: SchemaModel

      The model we need a predicate for.

    • flatEqualities: Record<string, any>

      An object holding field equalities to search for.

    Returns object & object

Static getPredicates

  • getPredicates<T>(predicate: ModelPredicate<T>, throwOnInvalid?: boolean): object
  • Looks for the storage predicate AST that corresponds to a given storage predicate key.

    The key must have been created internally by a DataStore utility method, such as ModelPredicate.createFromAST().

    Type parameters

    Parameters

    • predicate: ModelPredicate<T>

      The predicate reference to look up.

    • Default value throwOnInvalid: boolean = true

      Whether to throw an exception if the predicate isn't a valid DataStore predicate.

    Returns object

Static isValidPredicate

  • isValidPredicate<T>(predicate: any): predicate

Static transformGraphQLFilterNodeToPredicateAST

  • transformGraphQLFilterNodeToPredicateAST(gql: any): any
  • Accepts a GraphQL style filter predicate tree and transforms it into an AST that can be used for a storage adapter predicate. Example input:

    {
        and: [
            { name: { eq: "Bob Jones" } },
            { age: { between: [32, 64] } },
            { not: {
                or: [
                    { favoriteFood: { eq: 'pizza' } },
                    { favoriteFood: { eq: 'tacos' } },
                ]
            }}
        ]
    }

    Parameters

    • gql: any

      GraphQL style filter node.

    Returns any