The QuickBlox Developer Hub

Welcome to the QuickBlox developer hub. You'll find comprehensive guides and documentation to help you start working with QuickBlox as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Custom Objects

This is our new documentation for beta version of QuickBlox React Native SDK. Please contact our Customer Support Team to provide your feedback, suggestions, and requests to improve this page.

Custom Objects module provides flexibility to define any data structure (schema) you need. Schema is defined in QuickBlox Dashboard. The schema is called Class and contains field names and their type.

Create records

To create a single object, use the code snippet below.

const customObject = {
  className: 'RNCustomObject2',
  fields: {
    text: 'Lorem ipsum dolor sit amen',
    version: 7,
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    friendsIds: [ 12345, 12346, 12347 ]
  }
}

QB.objects
  .create(customObject)
  .then(function (cObject) { /* custom object created successfully */ })
  .catch(function (e) { /* handle error */ })

To create multiple objects, use the code snippet below.

const customObjects = {
  className: 'RNCustomObject2',
  objects: [{
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    text: 'Lorem ipsum dolor sit amen 1',
    version: 1500
  }, {
    friendsIds: [],
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    text: 'Lorem ipsum dolor sit amen 2',
    version: 1001
  }, {
    tags: [ '#test', '#customobjects', '#quickblox-react-native-sdk'],
    text: 'Lorem ipsum dolor sit amen 3',
    version: 13
  }]
}

QB.objects
  .create(customObjects)
  .then(function (cObjects) { /* custom objects created successfully */ })
  .catch(function (e) { /* handle error */ })

Retrieve records

To search for records of a particular class, apply the following code snippet.

const query = {
  className: 'RNCustomObject2',
  filter: {
    field: 'version',
    operator: QB.objects.OBJECTS_SEARCH_OPERATOR.FOR_TYPE.INTEGER.GTE,
    value: '1000'
  },
  sort: {
    ascending: false,
    field: 'created_at'
  }
}

QB.objects
  .get(query)
  .then(function (results) { /* records found */ })
  .catch(function (e) { /* handle error */ })

Retrieve records by IDs

To get records with a particular record ID, use the code snippet below.

const query = {
  className: 'RNCustomObject2',
  objectsIds: ['5d4175afa0eb4715cae5b63f']
}
QB.objects
  .get(query)
  .then(function (results) { /* records found by IDs */ })
  .catch(function (e) { /* handle error */ })

Update records

You can update a single record using the code snippet below.

const payload = {
  className: customObject.className,
  id: customObject.id,
  fields: {
    text: 'Lorem ipsum dolor sit amen UPDATED',
    tags: {
      operator: QB.objects.OBJECTS_UPDATE_OPERATOR.FOR_TYPE.ARRAY.ADD_TO_SET,
      value: '#update',
    },
    friendsIds: {
      operator: QB.objects.OBJECTS_UPDATE_OPERATOR.FOR_TYPE.ARRAY.PULL,
      pullFilter: QB.objects.PULL_FILTER.IN,
      value: currentUser.id,
    },
    version: {
      operator: QB.objects.OBJECTS_UPDATE_OPERATOR.FOR_TYPE.INTEGER.INC,
      value: '1'
    }
  }
}

QB.objects
  .update(payload)
  .then(function (updated) { /* custom object updated successfully */ })
  .catch(function (e) { /* handle error */ })

You can update multiple records using the code snippet below.

const payload = {
  className: object1.className,
  objects: [{
    id: object1.id,
    fields: {
      text: `Lorem ipsum dolor sit amen UPDATED 123`,
      tags: [ '#update' ],
    },
  }, {
    id: object2.id,
    fields: {
      friendsIds: [ 1001001, 1001010 ],
      version: 1250
    }
  }]
}

QB.objects
  .update(payload)
  .then(function (updated) { /* items updated successfully */ })
  .catch(function (e) { /* handle errror */ })

Delete records

To delete single a record, use the code snippet below.

const payload = {
  className: object.className,
  ids: object.id
}
QB.objects
  .remove(payload)
  .then(function () { /* removed successfully */ })
  .catch(function (e) { /* handle error */ })

To delete multiple records, use the code snippet below.

const payload = {
  className: object1.className,
  ids: [ object1.id, object2.id ]
}
QB.objects
  .remove(payload)
  .then(function () { /* removed successfully */ })
  .catch(function (e) { /* handle error */ })

Updated about a month ago

Custom Objects


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.