{"_id":"5735d3f7a430ed22001c5e90","parentDoc":null,"__v":22,"user":"54774c47f3736008009e9e0c","project":"54774d9af3736008009e9e0e","category":{"_id":"5735a52431a73b1700887ca0","project":"54774d9af3736008009e9e0e","__v":0,"version":"56a0bd9e3697d80d002ac5e7","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-05-13T09:57:56.274Z","from_sync":false,"order":13,"slug":"data-objects","title":"Data Objects"},"version":{"_id":"56a0bd9e3697d80d002ac5e7","project":"54774d9af3736008009e9e0e","__v":20,"createdAt":"2016-01-21T11:14:38.131Z","releaseDate":"2016-01-21T11:14:38.131Z","categories":["56a0bd9f3697d80d002ac5e8","56a0bd9f3697d80d002ac5e9","56a0bd9f3697d80d002ac5ea","56a0bd9f3697d80d002ac5eb","56b098a43a5b810d00745e3f","56b098da8f7a4f0d0029dd10","56d5a8ecf612b80b00fb69cd","570989853ab43c0e0072b2d6","571006aa10300c0e007f6133","5735a52431a73b1700887ca0","5744b0529e045c0e00b7a7a2","5744b1d0b56d431700d8a4fb","5744b1fb55d65a0e00b436e1","5744b218f9c7411700ce560e","5744b220f9c7411700ce560f","5744b2259e045c0e00b7a7a7","5744b22cf8b79f0e00de6a2d","5744b23155d65a0e00b436e4","5744b242c758290e00fbc235","5744b2569e045c0e00b7a7a8","5756a3f2bb92962900dafe3d","57ee23e81e42900e0014a42f","581c822c98676e0f00d240ef"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Sockets","version_clean":"1.1.0","version":"1.1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-13T13:17:43.221Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"## Chapter contents\n1. [Introduction](#introduction) \n2. [Data Object Fields](#data-object-fields)\n3. [Field Types](#field-types)\n4. [Adding custom (user defined) fields to Data Objects](#adding-custom-user-defined-fields-to-data-objects)\n5. [Summary](#summary) \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Introduction\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Because Data Objects on Syncano are schema based, you'll need to create a Data Class, where you can define a schema for your Data Objects. Creating Data Classes is described in [this chapter](doc:classes-overview).\"\n}\n[/block]\nYou can store data on Syncano using Data Objects. Data Objects are similar to `JSON` objects, that contain key-value pairs defined by you during Data Class creation. All of them also have default attributes defined by Syncano. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Data Object Fields\"\n}\n[/block]\nHere's how a simple Data Object representing a book could look like:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"id\\\": 55,\\n    \\\"author\\\": \\\"J. R. R. Tolkien\\\",\\n    \\\"title\\\": \\\"The Fellowship of the Ring\\\",\\n    \\\"text\\\": \\\"Hobbits and stuff\\\",\\n    \\\"created_at\\\": \\\"2015-02-05T13:38:33.829340Z\\\", \\n    \\\"updated_at\\\": \\\"2015-05-18T21:36:02.410173Z\\\", \\n    \\\"revision\\\": 2, \\n    \\\"owner\\\": null, \\n    \\\"owner_permissions\\\": \\\"none\\\", \\n    \\\"group\\\": null, \\n    \\\"group_permissions\\\": \\\"none\\\", \\n    \\\"other_permissions\\\": \\\"none\\\", \\n    \\\"channel\\\": null, \\n    \\\"channel_room\\\": null,  \\n    \\\"links\\\": {\\n        \\\"self\\\": \\\"/v1.1/instances/syncano/classes/test/objects/55/\\\"\\n    }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nApart from `author`, `title` and `text` fields, which you would define when creating a data class, there are several built-in fields, which every object has. They are listed in the table below:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Field\",\n    \"h-1\": \"Type\",\n    \"0-0\": \"id\",\n    \"0-1\": \"integer\",\n    \"1-0\": \"created_at\",\n    \"2-0\": \"updated_at\",\n    \"3-0\": \"revision\",\n    \"3-1\": \"integer\",\n    \"4-0\": \"links\",\n    \"1-1\": \"datetime\",\n    \"2-1\": \"datetime\",\n    \"4-1\": \"array\",\n    \"h-2\": \"Description\",\n    \"0-2\": \"Data Object identifier\",\n    \"1-2\": \"Data Object creation date in ISO 8601, UTC date time format with microsecond precision (i.e. 2015-02-13T07:32:05.659737Z)\",\n    \"2-2\": \"Data Object latest modification date in in ISO 8601, UTC date time format with microsecond precision (i.e. 2015-02-13T07:32:05.659737Z)\",\n    \"3-2\": \"Version of a Data Object. It increments every time a Data Object is updated in any way.\",\n    \"4-2\": \"[HATEOAS](http://stackoverflow.com/questions/9192648/hateoas-concise-description) Links.\"\n  },\n  \"cols\": 3,\n  \"rows\": 5\n}\n[/block]\nAs you can see, there are several fields that were not mentioned in the table above:\n- `owner`, `owner_permissions`, `group`, `group_permissions`, `other_permissions` - these fields relate to permissions system on Syncano. You can read about them later in the [Permissions Chapter](doc:permissions)\n- `channel` and `channel_room` - these fields can be used to take advantage of real-time communication features Syncano provides. You can read about the concept in depth in the [Realtime Communication](doc:realtime-communication) chapter.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Field Types\"\n}\n[/block]\nIn our book example, `author`, `title` and `text` fields are custom and were created by a Syncano user. These custom fields can have several different types:\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Type\",\n    \"h-1\": \"Description\",\n    \"h-2\": \"Limit\",\n    \"0-0\": \"`string`\",\n    \"1-0\": \"`text`\",\n    \"2-0\": \"`integer`\",\n    \"3-0\": \"`float`\",\n    \"6-0\": \"`boolean`\",\n    \"7-0\": \"`datetime`\",\n    \"8-0\": \"`file`\",\n    \"9-0\": \"`reference`\",\n    \"10-0\": \"`geopoint`\",\n    \"4-0\": \"`array`\",\n    \"5-0\": \"`object`\",\n    \"5-1\": \"an unordered collection of key:value pairs\",\n    \"4-1\": \"an ordered sequence of values\",\n    \"0-1\": \"double-quoted Unicode with backslash escaping\",\n    \"3-1\": \"Fractions like 0.3, -0.912 etc. Double precision field with up to 15 decimal digit precision\",\n    \"6-1\": \"`true` or `false`\",\n    \"2-1\": \"Digits 1-9, 0 and positive or negative\",\n    \"1-1\": \"double-quoted Unicode with backslash escaping\",\n    \"7-1\": \"ISO 8601, UTC date time format with microsecond precision (i.e. 2015-02-13T07:32:05.659737Z)\",\n    \"8-2\": \"128mb\",\n    \"0-2\": \"128 max character length\",\n    \"1-2\": \"32000 max character length\",\n    \"2-2\": \"32-bit (signed)\",\n    \"3-2\": \"64-bit\",\n    \"9-1\": \"Reference to a different Data Object\",\n    \"10-1\": \"longitude and latitude\",\n    \"8-1\": \"stored as a url\"\n  },\n  \"cols\": 3,\n  \"rows\": 11\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"A default value for any field type is `null`. What it means, is that when a Data Object is created and there's no value assigned to a custom property, it's value will be `null`.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Adding custom (user defined) fields to Data Objects\"\n}\n[/block]\nThe custom fields are defined when creating a Data Class that wraps your Data Objects. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/sfCcsQ0IQzs2QC1VBoZH_Field_types.png\",\n        \"Field_types.png\",\n        \"1279\",\n        \"655\",\n        \"#697c9e\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can read more about user-defined field types in the [Data Classes chapter](classes#section-types-of-class-schema-fields).\n\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Summary\"\n}\n[/block]\nYou should have an overview of what Data Objects are and what kind of data types can be stored in Data Objects. It's time to learn the [basics of adding, updating, deleting and listing Data Objects](basics).","excerpt":"In this chapter you will learn:\n- What are Data Objects\n- What's inside a Data Object","slug":"data-objects-overview","type":"basic","title":"Overview"}

Overview

In this chapter you will learn: - What are Data Objects - What's inside a Data Object

## Chapter contents 1. [Introduction](#introduction) 2. [Data Object Fields](#data-object-fields) 3. [Field Types](#field-types) 4. [Adding custom (user defined) fields to Data Objects](#adding-custom-user-defined-fields-to-data-objects) 5. [Summary](#summary) [block:api-header] { "type": "basic", "title": "Introduction" } [/block] [block:callout] { "type": "warning", "body": "Because Data Objects on Syncano are schema based, you'll need to create a Data Class, where you can define a schema for your Data Objects. Creating Data Classes is described in [this chapter](doc:classes-overview)." } [/block] You can store data on Syncano using Data Objects. Data Objects are similar to `JSON` objects, that contain key-value pairs defined by you during Data Class creation. All of them also have default attributes defined by Syncano. [block:api-header] { "type": "basic", "title": "Data Object Fields" } [/block] Here's how a simple Data Object representing a book could look like: [block:code] { "codes": [ { "code": "{\n \"id\": 55,\n \"author\": \"J. R. R. Tolkien\",\n \"title\": \"The Fellowship of the Ring\",\n \"text\": \"Hobbits and stuff\",\n \"created_at\": \"2015-02-05T13:38:33.829340Z\", \n \"updated_at\": \"2015-05-18T21:36:02.410173Z\", \n \"revision\": 2, \n \"owner\": null, \n \"owner_permissions\": \"none\", \n \"group\": null, \n \"group_permissions\": \"none\", \n \"other_permissions\": \"none\", \n \"channel\": null, \n \"channel_room\": null, \n \"links\": {\n \"self\": \"/v1.1/instances/syncano/classes/test/objects/55/\"\n }\n}", "language": "json" } ] } [/block] Apart from `author`, `title` and `text` fields, which you would define when creating a data class, there are several built-in fields, which every object has. They are listed in the table below: [block:parameters] { "data": { "h-0": "Field", "h-1": "Type", "0-0": "id", "0-1": "integer", "1-0": "created_at", "2-0": "updated_at", "3-0": "revision", "3-1": "integer", "4-0": "links", "1-1": "datetime", "2-1": "datetime", "4-1": "array", "h-2": "Description", "0-2": "Data Object identifier", "1-2": "Data Object creation date in ISO 8601, UTC date time format with microsecond precision (i.e. 2015-02-13T07:32:05.659737Z)", "2-2": "Data Object latest modification date in in ISO 8601, UTC date time format with microsecond precision (i.e. 2015-02-13T07:32:05.659737Z)", "3-2": "Version of a Data Object. It increments every time a Data Object is updated in any way.", "4-2": "[HATEOAS](http://stackoverflow.com/questions/9192648/hateoas-concise-description) Links." }, "cols": 3, "rows": 5 } [/block] As you can see, there are several fields that were not mentioned in the table above: - `owner`, `owner_permissions`, `group`, `group_permissions`, `other_permissions` - these fields relate to permissions system on Syncano. You can read about them later in the [Permissions Chapter](doc:permissions) - `channel` and `channel_room` - these fields can be used to take advantage of real-time communication features Syncano provides. You can read about the concept in depth in the [Realtime Communication](doc:realtime-communication) chapter. [block:api-header] { "type": "basic", "title": "Field Types" } [/block] In our book example, `author`, `title` and `text` fields are custom and were created by a Syncano user. These custom fields can have several different types: [block:parameters] { "data": { "h-0": "Type", "h-1": "Description", "h-2": "Limit", "0-0": "`string`", "1-0": "`text`", "2-0": "`integer`", "3-0": "`float`", "6-0": "`boolean`", "7-0": "`datetime`", "8-0": "`file`", "9-0": "`reference`", "10-0": "`geopoint`", "4-0": "`array`", "5-0": "`object`", "5-1": "an unordered collection of key:value pairs", "4-1": "an ordered sequence of values", "0-1": "double-quoted Unicode with backslash escaping", "3-1": "Fractions like 0.3, -0.912 etc. Double precision field with up to 15 decimal digit precision", "6-1": "`true` or `false`", "2-1": "Digits 1-9, 0 and positive or negative", "1-1": "double-quoted Unicode with backslash escaping", "7-1": "ISO 8601, UTC date time format with microsecond precision (i.e. 2015-02-13T07:32:05.659737Z)", "8-2": "128mb", "0-2": "128 max character length", "1-2": "32000 max character length", "2-2": "32-bit (signed)", "3-2": "64-bit", "9-1": "Reference to a different Data Object", "10-1": "longitude and latitude", "8-1": "stored as a url" }, "cols": 3, "rows": 11 } [/block] [block:callout] { "type": "info", "body": "A default value for any field type is `null`. What it means, is that when a Data Object is created and there's no value assigned to a custom property, it's value will be `null`." } [/block] [block:api-header] { "type": "basic", "title": "Adding custom (user defined) fields to Data Objects" } [/block] The custom fields are defined when creating a Data Class that wraps your Data Objects. [block:image] { "images": [ { "image": [ "https://files.readme.io/sfCcsQ0IQzs2QC1VBoZH_Field_types.png", "Field_types.png", "1279", "655", "#697c9e", "" ] } ] } [/block] You can read more about user-defined field types in the [Data Classes chapter](classes#section-types-of-class-schema-fields). [block:api-header] { "type": "basic", "title": "Summary" } [/block] You should have an overview of what Data Objects are and what kind of data types can be stored in Data Objects. It's time to learn the [basics of adding, updating, deleting and listing Data Objects](basics).