{"action":"created","comment":{"url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/comments/84611332","pull_request_review_id":5377845,"id":84611332,"diff_hunk":"@@ -1,335 +1,189 @@\n-<a name=\"overview\"></a>\n-## Overview\n-\n-Please make sure you know about and have already configured your skygear\n-[container](/js/guide#set-up-app) before you proceed.\n-\n-<a name=\"record\"></a>\n-### The Record Class\n-\n-- `Record` must have a type.\n-- Each `Record` object is like a dictionary with keys and values; keys will be\n-mapped to database column names, and values will be stored appropriately\n-based on the data type. Please refer to [Data Type](#data-type)\n-section within this guide for more information.\n-- `Record` will be owned by the currently logged in user.\n-- Each `Record` object has its unique `id` (combination of record type\n-  and uuid used in the database as `_id`).\n-- `Record` has reserved keys that cannot be used, such as `id` and `_id`.\n-Please refer to [Reserved Columns](#reserved) section for more.\n-\n-You can design different `Record` type to model your app. Just like defining\n-tables in SQL.\n-\n-``` javascript\n-const Note = skygear.Record.extend('note');\n-const Blog = skygear.Record.extend('blog');\n-\n-const note = new Note({ 'content': 'Hello World' });\n+<a name=\"what-are-records\"></a>\n+## What are Records?\n+In Skygear, you can store data using **Records**. They provide a reliable way store *structured*, *persistent* data on the backend.\n+\n+Each Skygear record is associated with a named **type** which is bound to an extendable data schema. In the JS SDK, records are simply JS objects.\n+\n+All Skygear records are also assigned a unique UUID during creation for identification.\n+\n+<a name=\"record-owner\"></a>\n+### Record Owner\n+By design, each Skygear record is associated a user for easy access control so you must be logged-in to be able to create and save records. However, if access control is not required, you can login as the anonymous user. \n+\n+Refer to the [User & Authentication][] section for more detail.\n+\n+<a name=\"record-object\"></a>\n+### Record Object\n+Skygear records are JS objects, you can easily create records using the following 2 lines:\n+```js\n+// define record type \"person\"\n+const PersonRecord = skygear.Record.extend(\"person\");\n+// create \"person\" record: bob\n+const bob = new PersonRecord({ name: \"bob\", age: 20 });\n+\n+{ // bob object:\n+  name: \"bob\"\n+  age: 20\n+  // read-only metadata provided by skygear:\n+  recordType: \"person\"\n+  id: \"person/45b0272b-41dc-483c-a07d-798a95cabbbd\"\n+  ownerID: \"7888d764-a20a-4c2c-89c2-8eb02de0a079\"\n+  createdAt: Mon Oct 17 2016 16:49:14 GMT+0800 (HKT)\n+  createdBy: \"7888d764-a20a-4c2c-89c2-8eb02de0a079\"\n+  updatedAt: Mon Oct 17 2016 16:49:14 GMT+0800 (HKT)\n+  updatedBy: \"7888d764-a20a-4c2c-89c2-8eb02de0a079\"\n+}\n ```\n+When creating Skygear records, you should avoid starting your type name with `_` and the fields names with either `_` or `$` as they are reserved by Skygear for internal usage. You should also avoid naming your fields the same as the metadata shown above.\n \n-### Record Database\n-\n-You will be provided with a private and a public database.\n+<a name=\"public-private-database\"></a>\n+## Public/Private Database\n+Skygear provides 2 places where you could save records: a `privateDB` that can only be accessed by the user and a `publicDB` that's controlled by access rules attached to each record. By default, every record in the `publicDB` is readable by everyone and only writable by its creator.\n \n-- Everything in the private database is truly private, regardless of what access\n-control entity you set to the record. In other words, each user has his own\n-private database, and only himself has access to it.\n-- Record saved at public database is by default public. Even without\n-logging in, records in the public database can be queried (but not updated).\n-To control the access, you may set different access control to the record.\n-- The database objects can be accessed with `skygear.publicDB` and\n-`skygear.privateDB`.\n+Refer to the [Access Control][] section for more detail.\n \n-<a name=\"basic-crud\"></a>\n-## Basic CRUD\n+<a name=\"sql-database-backend\"></a>\n+### SQL Database Backend\n+On the Skygear server backend, a relational SQL database is used to store your data. The record's type name is mapped to a table name while field names are mapped to table columns. You can view and modify skygear's data by connecting directly to the database.\n \n-### Creating a record\n-\n-You can save a public record to server as the following.\n-\n-``` javascript\n-skygear.publicDB.save(new Note({\n-  'content': 'Hello World!'\n-})).then((record) => {\n-  console.log(record);\n-}, (error) => {\n-  console.error(error);\n-});\n+<a name=\"save\"></a>\n+## Save\n+You can save skygear records using a single API call, here's how you could save the `bob` record created in the section [above][record object]:\n+```js\n+const savePromise = skygear.publicDB.save(bob);","path":"content/js/record.md","position":106,"original_position":106,"commit_id":"6dd8c2d201412aba427479c8535d68b7f8ffe020","original_commit_id":"6dd8c2d201412aba427479c8535d68b7f8ffe020","user":{"login":"bensonby","id":246195,"avatar_url":"https://avatars.githubusercontent.com/u/246195?v=3","gravatar_id":"","url":"https://api.github.com/users/bensonby","html_url":"https://github.com/bensonby","followers_url":"https://api.github.com/users/bensonby/followers","following_url":"https://api.github.com/users/bensonby/following{/other_user}","gists_url":"https://api.github.com/users/bensonby/gists{/gist_id}","starred_url":"https://api.github.com/users/bensonby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bensonby/subscriptions","organizations_url":"https://api.github.com/users/bensonby/orgs","repos_url":"https://api.github.com/users/bensonby/repos","events_url":"https://api.github.com/users/bensonby/events{/privacy}","received_events_url":"https://api.github.com/users/bensonby/received_events","type":"User","site_admin":false},"body":"Involving only 2 lines, we can add how to create `bob` here.","created_at":"2016-10-24T01:25:34Z","updated_at":"2016-10-24T01:26:00Z","html_url":"https://github.com/SkygearIO/skygear-doc/pull/365#discussion_r84611332","pull_request_url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365","_links":{"self":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/comments/84611332"},"html":{"href":"https://github.com/SkygearIO/skygear-doc/pull/365#discussion_r84611332"},"pull_request":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365"}}},"pull_request":{"url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365","id":89604491,"html_url":"https://github.com/SkygearIO/skygear-doc/pull/365","diff_url":"https://github.com/SkygearIO/skygear-doc/pull/365.diff","patch_url":"https://github.com/SkygearIO/skygear-doc/pull/365.patch","issue_url":"https://api.github.com/repos/SkygearIO/skygear-doc/issues/365","number":365,"state":"open","locked":false,"title":"#304 New records guide","user":{"login":"akiroz","id":8231917,"avatar_url":"https://avatars.githubusercontent.com/u/8231917?v=3","gravatar_id":"","url":"https://api.github.com/users/akiroz","html_url":"https://github.com/akiroz","followers_url":"https://api.github.com/users/akiroz/followers","following_url":"https://api.github.com/users/akiroz/following{/other_user}","gists_url":"https://api.github.com/users/akiroz/gists{/gist_id}","starred_url":"https://api.github.com/users/akiroz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akiroz/subscriptions","organizations_url":"https://api.github.com/users/akiroz/orgs","repos_url":"https://api.github.com/users/akiroz/repos","events_url":"https://api.github.com/users/akiroz/events{/privacy}","received_events_url":"https://api.github.com/users/akiroz/received_events","type":"User","site_admin":false},"body":"connects 304","created_at":"2016-10-17T11:20:29Z","updated_at":"2016-10-24T01:26:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"479d1f3094667ae2faa08ce7fb24c11a044ea96a","assignee":{"login":"bensonby","id":246195,"avatar_url":"https://avatars.githubusercontent.com/u/246195?v=3","gravatar_id":"","url":"https://api.github.com/users/bensonby","html_url":"https://github.com/bensonby","followers_url":"https://api.github.com/users/bensonby/followers","following_url":"https://api.github.com/users/bensonby/following{/other_user}","gists_url":"https://api.github.com/users/bensonby/gists{/gist_id}","starred_url":"https://api.github.com/users/bensonby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bensonby/subscriptions","organizations_url":"https://api.github.com/users/bensonby/orgs","repos_url":"https://api.github.com/users/bensonby/repos","events_url":"https://api.github.com/users/bensonby/events{/privacy}","received_events_url":"https://api.github.com/users/bensonby/received_events","type":"User","site_admin":false},"assignees":[{"login":"bensonby","id":246195,"avatar_url":"https://avatars.githubusercontent.com/u/246195?v=3","gravatar_id":"","url":"https://api.github.com/users/bensonby","html_url":"https://github.com/bensonby","followers_url":"https://api.github.com/users/bensonby/followers","following_url":"https://api.github.com/users/bensonby/following{/other_user}","gists_url":"https://api.github.com/users/bensonby/gists{/gist_id}","starred_url":"https://api.github.com/users/bensonby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bensonby/subscriptions","organizations_url":"https://api.github.com/users/bensonby/orgs","repos_url":"https://api.github.com/users/bensonby/repos","events_url":"https://api.github.com/users/bensonby/events{/privacy}","received_events_url":"https://api.github.com/users/bensonby/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365/commits","review_comments_url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365/comments","review_comment_url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SkygearIO/skygear-doc/issues/365/comments","statuses_url":"https://api.github.com/repos/SkygearIO/skygear-doc/statuses/6dd8c2d201412aba427479c8535d68b7f8ffe020","head":{"label":"akiroz:304-js-records","ref":"304-js-records","sha":"6dd8c2d201412aba427479c8535d68b7f8ffe020","user":{"login":"akiroz","id":8231917,"avatar_url":"https://avatars.githubusercontent.com/u/8231917?v=3","gravatar_id":"","url":"https://api.github.com/users/akiroz","html_url":"https://github.com/akiroz","followers_url":"https://api.github.com/users/akiroz/followers","following_url":"https://api.github.com/users/akiroz/following{/other_user}","gists_url":"https://api.github.com/users/akiroz/gists{/gist_id}","starred_url":"https://api.github.com/users/akiroz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akiroz/subscriptions","organizations_url":"https://api.github.com/users/akiroz/orgs","repos_url":"https://api.github.com/users/akiroz/repos","events_url":"https://api.github.com/users/akiroz/events{/privacy}","received_events_url":"https://api.github.com/users/akiroz/received_events","type":"User","site_admin":false},"repo":{"id":64447499,"name":"skygear-doc","full_name":"akiroz/skygear-doc","owner":{"login":"akiroz","id":8231917,"avatar_url":"https://avatars.githubusercontent.com/u/8231917?v=3","gravatar_id":"","url":"https://api.github.com/users/akiroz","html_url":"https://github.com/akiroz","followers_url":"https://api.github.com/users/akiroz/followers","following_url":"https://api.github.com/users/akiroz/following{/other_user}","gists_url":"https://api.github.com/users/akiroz/gists{/gist_id}","starred_url":"https://api.github.com/users/akiroz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akiroz/subscriptions","organizations_url":"https://api.github.com/users/akiroz/orgs","repos_url":"https://api.github.com/users/akiroz/repos","events_url":"https://api.github.com/users/akiroz/events{/privacy}","received_events_url":"https://api.github.com/users/akiroz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akiroz/skygear-doc","description":"Doc site for all the platform guides of Skygear.","fork":true,"url":"https://api.github.com/repos/akiroz/skygear-doc","forks_url":"https://api.github.com/repos/akiroz/skygear-doc/forks","keys_url":"https://api.github.com/repos/akiroz/skygear-doc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akiroz/skygear-doc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akiroz/skygear-doc/teams","hooks_url":"https://api.github.com/repos/akiroz/skygear-doc/hooks","issue_events_url":"https://api.github.com/repos/akiroz/skygear-doc/issues/events{/number}","events_url":"https://api.github.com/repos/akiroz/skygear-doc/events","assignees_url":"https://api.github.com/repos/akiroz/skygear-doc/assignees{/user}","branches_url":"https://api.github.com/repos/akiroz/skygear-doc/branches{/branch}","tags_url":"https://api.github.com/repos/akiroz/skygear-doc/tags","blobs_url":"https://api.github.com/repos/akiroz/skygear-doc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akiroz/skygear-doc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akiroz/skygear-doc/git/refs{/sha}","trees_url":"https://api.github.com/repos/akiroz/skygear-doc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akiroz/skygear-doc/statuses/{sha}","languages_url":"https://api.github.com/repos/akiroz/skygear-doc/languages","stargazers_url":"https://api.github.com/repos/akiroz/skygear-doc/stargazers","contributors_url":"https://api.github.com/repos/akiroz/skygear-doc/contributors","subscribers_url":"https://api.github.com/repos/akiroz/skygear-doc/subscribers","subscription_url":"https://api.github.com/repos/akiroz/skygear-doc/subscription","commits_url":"https://api.github.com/repos/akiroz/skygear-doc/commits{/sha}","git_commits_url":"https://api.github.com/repos/akiroz/skygear-doc/git/commits{/sha}","comments_url":"https://api.github.com/repos/akiroz/skygear-doc/comments{/number}","issue_comment_url":"https://api.github.com/repos/akiroz/skygear-doc/issues/comments{/number}","contents_url":"https://api.github.com/repos/akiroz/skygear-doc/contents/{+path}","compare_url":"https://api.github.com/repos/akiroz/skygear-doc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akiroz/skygear-doc/merges","archive_url":"https://api.github.com/repos/akiroz/skygear-doc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akiroz/skygear-doc/downloads","issues_url":"https://api.github.com/repos/akiroz/skygear-doc/issues{/number}","pulls_url":"https://api.github.com/repos/akiroz/skygear-doc/pulls{/number}","milestones_url":"https://api.github.com/repos/akiroz/skygear-doc/milestones{/number}","notifications_url":"https://api.github.com/repos/akiroz/skygear-doc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akiroz/skygear-doc/labels{/name}","releases_url":"https://api.github.com/repos/akiroz/skygear-doc/releases{/id}","deployments_url":"https://api.github.com/repos/akiroz/skygear-doc/deployments","created_at":"2016-07-29T03:31:35Z","updated_at":"2016-07-29T03:31:36Z","pushed_at":"2016-10-21T19:24:42Z","git_url":"git://github.com/akiroz/skygear-doc.git","ssh_url":"git@github.com:akiroz/skygear-doc.git","clone_url":"https://github.com/akiroz/skygear-doc.git","svn_url":"https://github.com/akiroz/skygear-doc","homepage":"https://docs.skygear.io/","size":4378,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SkygearIO:master","ref":"master","sha":"4b592aba7fba2b2fad6e22dbdcc4491731a76376","user":{"login":"SkygearIO","id":15025887,"avatar_url":"https://avatars.githubusercontent.com/u/15025887?v=3","gravatar_id":"","url":"https://api.github.com/users/SkygearIO","html_url":"https://github.com/SkygearIO","followers_url":"https://api.github.com/users/SkygearIO/followers","following_url":"https://api.github.com/users/SkygearIO/following{/other_user}","gists_url":"https://api.github.com/users/SkygearIO/gists{/gist_id}","starred_url":"https://api.github.com/users/SkygearIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SkygearIO/subscriptions","organizations_url":"https://api.github.com/users/SkygearIO/orgs","repos_url":"https://api.github.com/users/SkygearIO/repos","events_url":"https://api.github.com/users/SkygearIO/events{/privacy}","received_events_url":"https://api.github.com/users/SkygearIO/received_events","type":"Organization","site_admin":false},"repo":{"id":56206030,"name":"skygear-doc","full_name":"SkygearIO/skygear-doc","owner":{"login":"SkygearIO","id":15025887,"avatar_url":"https://avatars.githubusercontent.com/u/15025887?v=3","gravatar_id":"","url":"https://api.github.com/users/SkygearIO","html_url":"https://github.com/SkygearIO","followers_url":"https://api.github.com/users/SkygearIO/followers","following_url":"https://api.github.com/users/SkygearIO/following{/other_user}","gists_url":"https://api.github.com/users/SkygearIO/gists{/gist_id}","starred_url":"https://api.github.com/users/SkygearIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SkygearIO/subscriptions","organizations_url":"https://api.github.com/users/SkygearIO/orgs","repos_url":"https://api.github.com/users/SkygearIO/repos","events_url":"https://api.github.com/users/SkygearIO/events{/privacy}","received_events_url":"https://api.github.com/users/SkygearIO/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SkygearIO/skygear-doc","description":"Doc site for all the platform guides of Skygear.","fork":false,"url":"https://api.github.com/repos/SkygearIO/skygear-doc","forks_url":"https://api.github.com/repos/SkygearIO/skygear-doc/forks","keys_url":"https://api.github.com/repos/SkygearIO/skygear-doc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SkygearIO/skygear-doc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SkygearIO/skygear-doc/teams","hooks_url":"https://api.github.com/repos/SkygearIO/skygear-doc/hooks","issue_events_url":"https://api.github.com/repos/SkygearIO/skygear-doc/issues/events{/number}","events_url":"https://api.github.com/repos/SkygearIO/skygear-doc/events","assignees_url":"https://api.github.com/repos/SkygearIO/skygear-doc/assignees{/user}","branches_url":"https://api.github.com/repos/SkygearIO/skygear-doc/branches{/branch}","tags_url":"https://api.github.com/repos/SkygearIO/skygear-doc/tags","blobs_url":"https://api.github.com/repos/SkygearIO/skygear-doc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SkygearIO/skygear-doc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SkygearIO/skygear-doc/git/refs{/sha}","trees_url":"https://api.github.com/repos/SkygearIO/skygear-doc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SkygearIO/skygear-doc/statuses/{sha}","languages_url":"https://api.github.com/repos/SkygearIO/skygear-doc/languages","stargazers_url":"https://api.github.com/repos/SkygearIO/skygear-doc/stargazers","contributors_url":"https://api.github.com/repos/SkygearIO/skygear-doc/contributors","subscribers_url":"https://api.github.com/repos/SkygearIO/skygear-doc/subscribers","subscription_url":"https://api.github.com/repos/SkygearIO/skygear-doc/subscription","commits_url":"https://api.github.com/repos/SkygearIO/skygear-doc/commits{/sha}","git_commits_url":"https://api.github.com/repos/SkygearIO/skygear-doc/git/commits{/sha}","comments_url":"https://api.github.com/repos/SkygearIO/skygear-doc/comments{/number}","issue_comment_url":"https://api.github.com/repos/SkygearIO/skygear-doc/issues/comments{/number}","contents_url":"https://api.github.com/repos/SkygearIO/skygear-doc/contents/{+path}","compare_url":"https://api.github.com/repos/SkygearIO/skygear-doc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SkygearIO/skygear-doc/merges","archive_url":"https://api.github.com/repos/SkygearIO/skygear-doc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SkygearIO/skygear-doc/downloads","issues_url":"https://api.github.com/repos/SkygearIO/skygear-doc/issues{/number}","pulls_url":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls{/number}","milestones_url":"https://api.github.com/repos/SkygearIO/skygear-doc/milestones{/number}","notifications_url":"https://api.github.com/repos/SkygearIO/skygear-doc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SkygearIO/skygear-doc/labels{/name}","releases_url":"https://api.github.com/repos/SkygearIO/skygear-doc/releases{/id}","deployments_url":"https://api.github.com/repos/SkygearIO/skygear-doc/deployments","created_at":"2016-04-14T04:00:08Z","updated_at":"2016-09-04T22:00:12Z","pushed_at":"2016-10-21T19:24:42Z","git_url":"git://github.com/SkygearIO/skygear-doc.git","ssh_url":"git@github.com:SkygearIO/skygear-doc.git","clone_url":"https://github.com/SkygearIO/skygear-doc.git","svn_url":"https://github.com/SkygearIO/skygear-doc","homepage":"https://docs.skygear.io/","size":4514,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":48,"forks":12,"open_issues":48,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365"},"html":{"href":"https://github.com/SkygearIO/skygear-doc/pull/365"},"issue":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/issues/365"},"comments":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/issues/365/comments"},"review_comments":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365/comments"},"review_comment":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/pulls/365/commits"},"statuses":{"href":"https://api.github.com/repos/SkygearIO/skygear-doc/statuses/6dd8c2d201412aba427479c8535d68b7f8ffe020"}}}}
{"actor":{"display_login":"bensonby"}}