How to use the rambdax.has function in rambdax

To help you get started, we’ve selected a few rambdax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
table: TableName,
  query: LokiRawQuery,
  originalConditions: Where[], // Needed for column comparisons
  mapKey: ColumnName,
  joinKey: ColumnName,
}>

export type LokiQuery = $Exact<{
  table: TableName,
  query: LokiRawQuery,
  joins: LokiJoin[],
}>

const getComparisonRight: ComparisonRight => CompoundValue = (cond([
  [has('value'), prop('value')],
  [has('values'), prop('values')],
  [has('column'), () => invariant(false, 'Column comparisons unimplemented!')], // TODO: !!
]): any)

// TODO: It's probably possible to improve performance of those operators by making them
// binary-search compatible (i.e. don't use $and, $not)
// TODO: We might be able to use $jgt, $jbetween, etc. — but ensure the semantics are right
// and it won't break indexing

type OperatorFunction = CompoundValue => LokiRawQuery

const weakNotEqual: OperatorFunction = value => ({ $not: { $aeq: value } })

const noNullComparisons: OperatorFunction => OperatorFunction = operator => value => ({
  $and: [operator(value), weakNotEqual(null)],
})
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
export type LokiJoin = $Exact<{
  table: TableName,
  query: LokiRawQuery,
  originalConditions: Where[], // Needed for column comparisons
  mapKey: ColumnName,
  joinKey: ColumnName,
}>

export type LokiQuery = $Exact<{
  table: TableName,
  query: LokiRawQuery,
  joins: LokiJoin[],
}>

const getComparisonRight: ComparisonRight => CompoundValue = (cond([
  [has('value'), prop('value')],
  [has('values'), prop('values')],
  [has('column'), () => invariant(false, 'Column comparisons unimplemented!')], // TODO: !!
]): any)

// TODO: It's probably possible to improve performance of those operators by making them
// binary-search compatible (i.e. don't use $and, $not)
// TODO: We might be able to use $jgt, $jbetween, etc. — but ensure the semantics are right
// and it won't break indexing

type OperatorFunction = CompoundValue => LokiRawQuery

const weakNotEqual: OperatorFunction = value => ({ $not: { $aeq: value } })

const noNullComparisons: OperatorFunction => OperatorFunction = operator => value => ({
  $and: [operator(value), weakNotEqual(null)],
})
github Nozbe / WatermelonDB / src / QueryDescription / index.js View on Github external
export function queryWithoutDeleted(query: QueryDescription): QueryDescription {
  const { join, where: whereConditions } = query

  return {
    join: [...join, ...joinsWithoutDeleted(join)],
    where: [...whereConditions, whereNotDeleted],
  }
}

const isNotObject = complement(isObject)

const searchForColumnComparisons: any => boolean = cond([
  [is(Array), any(value => searchForColumnComparisons(value))], // dig deeper into arrays
  [isNotObject, F], // bail if primitive value
  [has('column'), T], // bingo!
  [
    T,
    pipe(
      // dig deeper into objects
      getValues,
      any(value => searchForColumnComparisons(value)),
    ),
  ],
])

export function hasColumnComparisons(conditions: Where[]): boolean {
  return searchForColumnComparisons(conditions)
}
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
query: LokiRawQuery,
  originalConditions: Where[], // Needed for column comparisons
  mapKey: ColumnName,
  joinKey: ColumnName,
}>

export type LokiQuery = $Exact<{
  table: TableName,
  query: LokiRawQuery,
  joins: LokiJoin[],
}>

const getComparisonRight: ComparisonRight => CompoundValue = (cond([
  [has('value'), prop('value')],
  [has('values'), prop('values')],
  [has('column'), () => invariant(false, 'Column comparisons unimplemented!')], // TODO: !!
]): any)

// TODO: It's probably possible to improve performance of those operators by making them
// binary-search compatible (i.e. don't use $and, $not)
// TODO: We might be able to use $jgt, $jbetween, etc. — but ensure the semantics are right
// and it won't break indexing

type OperatorFunction = CompoundValue => LokiRawQuery

const weakNotEqual: OperatorFunction = value => ({ $not: { $aeq: value } })

const noNullComparisons: OperatorFunction => OperatorFunction = operator => value => ({
  $and: [operator(value), weakNotEqual(null)],
})

const like: OperatorFunction = value => {
github Nozbe / WatermelonDB / src / adapters / lokijs / worker / encodeQuery / index.js View on Github external
const encodeWhereDescription: (WhereDescription | On) => LokiRawQuery = ({ left, comparison }) =>
  // HACK: If this is a column comparison condition, ignore it (assume it evaluates to true)
  // The column comparison will actually be performed during the refining pass with a matcher func
  has('column', comparison.right)
    ? hackAlwaysTrueCondition
    : objOf(left, encodeComparison(comparison))
github Nozbe / WatermelonDB / src / observation / encodeMatcher / index.js View on Github external
) => $FlowFixMe = element =>
  cond([
    [has('value'), prop('value')],
    [has('values'), prop('values')],
    [has('column'), arg => element._raw[arg.column]],
  ])
github Nozbe / WatermelonDB / src / observation / encodeMatcher / index.js View on Github external
) => $FlowFixMe = element =>
  cond([
    [has('value'), prop('value')],
    [has('values'), prop('values')],
    [has('column'), arg => element._raw[arg.column]],
  ])
github Nozbe / WatermelonDB / src / observation / encodeMatcher / index.js View on Github external
) => $FlowFixMe = element =>
  cond([
    [has('value'), prop('value')],
    [has('values'), prop('values')],
    [has('column'), arg => element._raw[arg.column]],
  ])