Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kingstinct/react-native-healthkit/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Query options types provide flexible filtering, pagination, and sorting capabilities for HealthKit data queries. These types allow you to specify date ranges, metadata filters, sample limits, and sort orders.

GenericQueryOptions

Base interface for all query options.
interface GenericQueryOptions {
  filter?: FilterForSamples
  limit: number
}
filter
FilterForSamples
Filter criteria for samples. See FilterForSamples for details.
limit
number
required
Maximum number of samples to return. Specify -1, 0, or any non-positive number to fetch all samples.

QueryOptionsWithAnchor

Query options with anchor-based pagination support.
interface QueryOptionsWithAnchor extends GenericQueryOptions {
  anchor?: string
}
anchor
string
Pagination anchor from a previous query result. Used to fetch the next batch of results.

QueryOptionsWithSortOrder

Query options with sort order control.
interface QueryOptionsWithSortOrder extends GenericQueryOptions {
  ascending?: boolean
}
ascending
boolean
Sort order for results. true for ascending (oldest first), false for descending (newest first).

QueryOptionsWithSortOrderAndUnit

Query options with sort order and unit specification.
interface QueryOptionsWithSortOrderAndUnit extends QueryOptionsWithSortOrder {
  unit?: string
}
unit
string
Unit for quantity values. See Units for valid unit strings.

QueryOptionsWithAnchorAndUnit

Query options with anchor-based pagination and unit specification.
interface QueryOptionsWithAnchorAndUnit extends QueryOptionsWithAnchor {
  unit?: string
}
unit
string
Unit for quantity values. See Units for valid unit strings.

FilterForSamples

Comprehensive filter criteria for HealthKit samples.
interface FilterForSamples extends FilterForSamplesBase {
  sources?: SourceProxy[]
  OR?: FilterForSamplesBase[]
  NOT?: FilterForSamplesBase[]
  AND?: FilterForSamplesBase[]
}
sources
SourceProxy[]
Filter by specific data sources.
OR
FilterForSamplesBase[]
Array of filter conditions where at least one must match.
NOT
FilterForSamplesBase[]
Array of filter conditions that must not match.
AND
FilterForSamplesBase[]
Array of filter conditions that all must match.

FilterForSamplesBase

Base filter criteria for samples.
interface FilterForSamplesBase {
  uuid?: string
  uuids?: string[]
  metadata?: PredicateWithMetadataKey
  date?: DateFilter
  workout?: WorkoutProxy
  sources?: SourceProxy[]
}
uuid
string
Filter by a specific sample UUID.
uuids
string[]
Filter by multiple sample UUIDs.
metadata
PredicateWithMetadataKey
Filter by metadata key-value pairs. See PredicateWithMetadataKey.
date
DateFilter
Filter by date range. See DateFilter.
workout
WorkoutProxy
Filter samples associated with a specific workout.
sources
SourceProxy[]
Filter by data sources.

DateFilter

Filter samples by date range.
interface DateFilter {
  startDate?: Date
  endDate?: Date
  strictEndDate?: boolean
  strictStartDate?: boolean
}
startDate
Date
Start of the date range (inclusive by default).
endDate
Date
End of the date range (inclusive by default).
strictEndDate
boolean
When true, samples must end before the endDate (exclusive).
strictStartDate
boolean
When true, samples must start after the startDate (exclusive).

PredicateWithMetadataKey

Filter by metadata key-value pairs with comparison operators.
interface PredicateWithMetadataKey {
  withMetadataKey: string
  operatorType?: ComparisonPredicateOperator
  value?: string | number | Date | boolean
}
withMetadataKey
string
required
The metadata key to filter by.
operatorType
ComparisonPredicateOperator
Comparison operator for the filter. See ComparisonPredicateOperator.
value
string | number | Date | boolean
The value to compare against.

ComparisonPredicateOperator

Comparison operators for metadata filtering.
enum ComparisonPredicateOperator {
  lessThan = 0,
  lessThanOrEqualTo = 1,
  greaterThan = 2,
  greaterThanOrEqualTo = 3,
  equalTo = 4,
  notEqualTo = 5,
  matches = 6,
  like = 7,
  beginsWith = 8,
  endsWith = 9,
  IN = 10,
  customSelector = 11,
  contains = 99,
  between = 100,
}

Numeric Comparisons

  • lessThan - Value is less than the specified value
  • lessThanOrEqualTo - Value is less than or equal to the specified value
  • greaterThan - Value is greater than the specified value
  • greaterThanOrEqualTo - Value is greater than or equal to the specified value
  • equalTo - Value equals the specified value
  • notEqualTo - Value does not equal the specified value

String Comparisons

  • matches - String matches a regular expression pattern
  • like - String matches a pattern with wildcards
  • beginsWith - String begins with the specified value
  • endsWith - String ends with the specified value
  • contains - String contains the specified value

Collection Comparisons

  • IN - Value is in the specified collection
  • between - Value is between two specified values

Advanced

  • customSelector - Use a custom selector for comparison

Example Usage

Basic Query with Limit

const options: GenericQueryOptions = {
  limit: 10
}

Date Range Filter

const options: QueryOptionsWithSortOrder = {
  filter: {
    date: {
      startDate: new Date('2024-01-01'),
      endDate: new Date('2024-12-31')
    }
  },
  limit: 100,
  ascending: false
}

Metadata Filter

const options: QueryOptionsWithAnchor = {
  filter: {
    metadata: {
      withMetadataKey: 'HKWasUserEntered',
      operatorType: ComparisonPredicateOperator.equalTo,
      value: true
    }
  },
  limit: 50
}

Complex Filter with Logic

const options: QueryOptionsWithSortOrder = {
  filter: {
    OR: [
      {
        date: {
          startDate: new Date('2024-01-01'),
          endDate: new Date('2024-01-31')
        }
      },
      {
        metadata: {
          withMetadataKey: 'HKWasUserEntered',
          operatorType: ComparisonPredicateOperator.equalTo,
          value: true
        }
      }
    ]
  },
  limit: -1, // Fetch all
  ascending: true
}

Anchor-based Pagination

// First query
const firstOptions: QueryOptionsWithAnchor = {
  limit: 20
}

const firstResult = await queryHealthKitData(firstOptions)

// Next page
const nextOptions: QueryOptionsWithAnchor = {
  limit: 20,
  anchor: firstResult.newAnchor
}

const nextResult = await queryHealthKitData(nextOptions)

Build docs developers (and LLMs) love