{"__v":25,"_id":"5744b76da5961b0e00241b6d","category":{"__v":0,"_id":"5744b218f9c7411700ce560e","project":"54774d9af3736008009e9e0e","version":"56a0bd9e3697d80d002ac5e7","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-05-24T19:57:12.539Z","from_sync":false,"order":12,"slug":"classes","title":"Data Classes"},"parentDoc":null,"project":"54774d9af3736008009e9e0e","user":"56703d17e10ecb0d0004eed8","version":{"__v":20,"_id":"56a0bd9e3697d80d002ac5e7","project":"54774d9af3736008009e9e0e","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":["576943585fd53d1900d81c49"],"next":{"pages":[],"description":""},"createdAt":"2016-05-24T20:19:57.447Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"Each Data Class you create can have many different types of fields. These \"fields\" are properties that each Data Object inside this Data Class will contain, with `empty` as a default.\n\nLet's say you have a `person` Data Class. Each `person` data object can have a `name`, `age`, or maybe `height` field. You could also add a `photo` field for them. Each of those properties will be a field in the schema of that data class.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Data Class Schema\"\n}\n[/block]\nThe `Class schema` is the set of fields you would like to use in a Data Object. In Syncano, the `Data Class schema` is defined as a JSON list. Below we have an example JSON list for the `Data Class schema` of a book.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[  \\n  {  \\n    \\\"name\\\":\\\"book_title\\\",\\n    \\\"type\\\":\\\"string\\\"\\n   },\\n  {\\n  \\t\\\"name\\\":\\\"publish_date\\\",\\n    \\\"type\\\":\\\"datetime\\\"\\n  },\\n  {\\n    \\\"name\\\":\\\"total_pages\\\",\\n    \\\"type\\\":\\\"integer\\\"\\n  },\\n  {\\n    \\\"name\\\":\\\"non-fiction\\\",\\n    \\\"type\\\":\\\"boolean\\\"\\n  },\\n  {  \\n    \\\"name\\\":\\\"author\\\",\\n    \\\"type\\\":\\\"reference\\\",\\n    \\\"target\\\":\\\"author\\\"\\n  }\\n]\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThe `name` is the name of the field, and `type` is what kind of field it is such as `string`, `integer`, or even `file`! You'll also notice `target`. This field is actually a reference or relation to another Data Class. [Read more about references & relations here](doc:relations).\n\n### Types of Data Class Schema Fields\n\nThe following types of fields are supported in data class schema:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"field type\",\n    \"h-2\": \"example\",\n    \"0-0\": \"**string**\",\n    \"1-0\": \"**text**\",\n    \"2-0\": \"**integer**\",\n    \"3-0\": \"**float**\",\n    \"4-0\": \"**boolean**\",\n    \"5-0\": \"**datetime**\",\n    \"6-0\": \"**file**\",\n    \"7-0\": \"**reference**\",\n    \"0-2\": \"*This is my short book description.*\",\n    \"1-2\": \"*This is my books long description... and it can be a very long string.*\",\n    \"2-2\": \"*1337*\",\n    \"3-2\": \"*2.25*\",\n    \"4-2\": \"*true* or *false*\",\n    \"h-1\": \"description\",\n    \"0-1\": \"text field limited to 128 chars\",\n    \"1-1\": \"text field limited to 32000 chars\",\n    \"2-1\": \"number field\",\n    \"3-1\": \"floating point field\",\n    \"4-1\": \"boolean field\",\n    \"6-1\": \"binary data, max 128MB\",\n    \"7-2\": \"*65356*\",\n    \"7-1\": \"reference to Data Object (related Data Object ID)\",\n    \"5-1\": \"date in UTC format\",\n    \"5-2\": \"2015-02-22T05:09:244327Z\",\n    \"8-0\": \"**array**\",\n    \"9-0\": \"**object**\",\n    \"8-1\": \"array field of string types, int, boolean and float\",\n    \"8-2\": \"*[1, 2, 3, 4]*\",\n    \"9-1\": \"object field - JSON like\",\n    \"9-2\": \"*{\\n    \\\"attributeA\\\": \\\"A\\\",\\n    \\\"attributeB\\\": \\\"B\\\",\\n}*\",\n    \"6-2\": \"_Images, JSON, etc._\",\n    \"10-0\": \"**geopoint**\",\n    \"10-1\": \"geographic coordinates field\\nValid ranges:\\nLatitude: -89 to 89\\nLongitude -179 to 179\",\n    \"10-2\": \"*{\\n\\\"latitude\\\": 66.5433889, \\\"longitude\\\":25.8447679\\n}*\",\n    \"11-0\": \"**relation**\",\n    \"11-1\": \"reference to Data Objects (related to more than one Data Object ID)\",\n    \"11-2\": \"*12312, 3213, 8422*\"\n  },\n  \"cols\": 3,\n  \"rows\": 12\n}\n[/block]\n### Reference field\n\nIf a field in the schema is of type `reference`, there has to be a specified target. A Target can either be self or a name of another data class. [Read more about references & relations here](doc:relations).\n\n### Indexes\n\nIndexes are necessary if you want to filter or order data objects based on a chosen field.\nYou can add indexes to _most_ of the field types. **Types without indexes are:**\n\n- text\n- file\n\n[Read more about indexes here](doc:data-objects-filtering-ordering).\n\nBelow is an example of a schema with indexes:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[  \\n   {  \\n      \\\"name\\\":\\\"title\\\",\\n      \\\"type\\\":\\\"string\\\",\\n      \\\"order_index\\\":true,\\n      \\\"filter_index\\\":true\\n   },\\n   {  \\n      \\\"name\\\":\\\"release_year\\\",\\n      \\\"type\\\":\\\"integer\\\",\\n      \\\"order_index\\\":true,\\n      \\\"filter_index\\\":true\\n   },\\n   {  \\n      \\\"name\\\":\\\"price\\\",\\n      \\\"type\\\":\\\"float\\\",\\n      \\\"order_index\\\":true,\\n      \\\"filter_index\\\":true\\n   },\\n   {  \\n      \\\"name\\\":\\\"author\\\",\\n      \\\"type\\\":\\\"reference\\\",\\n      \\\"order_index\\\":true,\\n      \\\"filter_index\\\":true,\\n      \\\"target\\\":\\\"Author\\\"\\n   }\\n]\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Learn More\",\n  \"body\": \"For more details about the available methods for data classes, visit the [Data Classes API reference](http://docs.syncano.com/v0.1.1/docs/classes-list).\"\n}\n[/block]","excerpt":"In this chapter you will learn about the different types of fields a Data Class supports","slug":"classes-data-field-types","type":"basic","title":"Data Field Types"}

Data Field Types

In this chapter you will learn about the different types of fields a Data Class supports

Each Data Class you create can have many different types of fields. These "fields" are properties that each Data Object inside this Data Class will contain, with `empty` as a default. Let's say you have a `person` Data Class. Each `person` data object can have a `name`, `age`, or maybe `height` field. You could also add a `photo` field for them. Each of those properties will be a field in the schema of that data class. [block:api-header] { "type": "basic", "title": "Data Class Schema" } [/block] The `Class schema` is the set of fields you would like to use in a Data Object. In Syncano, the `Data Class schema` is defined as a JSON list. Below we have an example JSON list for the `Data Class schema` of a book. [block:code] { "codes": [ { "code": "[ \n { \n \"name\":\"book_title\",\n \"type\":\"string\"\n },\n {\n \t\"name\":\"publish_date\",\n \"type\":\"datetime\"\n },\n {\n \"name\":\"total_pages\",\n \"type\":\"integer\"\n },\n {\n \"name\":\"non-fiction\",\n \"type\":\"boolean\"\n },\n { \n \"name\":\"author\",\n \"type\":\"reference\",\n \"target\":\"author\"\n }\n]", "language": "json" } ] } [/block] The `name` is the name of the field, and `type` is what kind of field it is such as `string`, `integer`, or even `file`! You'll also notice `target`. This field is actually a reference or relation to another Data Class. [Read more about references & relations here](doc:relations). ### Types of Data Class Schema Fields The following types of fields are supported in data class schema: [block:parameters] { "data": { "h-0": "field type", "h-2": "example", "0-0": "**string**", "1-0": "**text**", "2-0": "**integer**", "3-0": "**float**", "4-0": "**boolean**", "5-0": "**datetime**", "6-0": "**file**", "7-0": "**reference**", "0-2": "*This is my short book description.*", "1-2": "*This is my books long description... and it can be a very long string.*", "2-2": "*1337*", "3-2": "*2.25*", "4-2": "*true* or *false*", "h-1": "description", "0-1": "text field limited to 128 chars", "1-1": "text field limited to 32000 chars", "2-1": "number field", "3-1": "floating point field", "4-1": "boolean field", "6-1": "binary data, max 128MB", "7-2": "*65356*", "7-1": "reference to Data Object (related Data Object ID)", "5-1": "date in UTC format", "5-2": "2015-02-22T05:09:244327Z", "8-0": "**array**", "9-0": "**object**", "8-1": "array field of string types, int, boolean and float", "8-2": "*[1, 2, 3, 4]*", "9-1": "object field - JSON like", "9-2": "*{\n \"attributeA\": \"A\",\n \"attributeB\": \"B\",\n}*", "6-2": "_Images, JSON, etc._", "10-0": "**geopoint**", "10-1": "geographic coordinates field\nValid ranges:\nLatitude: -89 to 89\nLongitude -179 to 179", "10-2": "*{\n\"latitude\": 66.5433889, \"longitude\":25.8447679\n}*", "11-0": "**relation**", "11-1": "reference to Data Objects (related to more than one Data Object ID)", "11-2": "*12312, 3213, 8422*" }, "cols": 3, "rows": 12 } [/block] ### Reference field If a field in the schema is of type `reference`, there has to be a specified target. A Target can either be self or a name of another data class. [Read more about references & relations here](doc:relations). ### Indexes Indexes are necessary if you want to filter or order data objects based on a chosen field. You can add indexes to _most_ of the field types. **Types without indexes are:** - text - file [Read more about indexes here](doc:data-objects-filtering-ordering). Below is an example of a schema with indexes: [block:code] { "codes": [ { "code": "[ \n { \n \"name\":\"title\",\n \"type\":\"string\",\n \"order_index\":true,\n \"filter_index\":true\n },\n { \n \"name\":\"release_year\",\n \"type\":\"integer\",\n \"order_index\":true,\n \"filter_index\":true\n },\n { \n \"name\":\"price\",\n \"type\":\"float\",\n \"order_index\":true,\n \"filter_index\":true\n },\n { \n \"name\":\"author\",\n \"type\":\"reference\",\n \"order_index\":true,\n \"filter_index\":true,\n \"target\":\"Author\"\n }\n]", "language": "json" } ] } [/block] [block:callout] { "type": "info", "title": "Learn More", "body": "For more details about the available methods for data classes, visit the [Data Classes API reference](http://docs.syncano.com/v0.1.1/docs/classes-list)." } [/block]