Full Example: Database
A photo sharing application is the database example on purpose: it is the best way to show what the Skapi database can do, because one real-world app exercises the whole capability at once. Posts are records with a photo file attached, a private post lives in its own access group, a like is a reference from one record to another, a comment hangs on a compound index, tags and reserved indexes drive every view, and subscriptions feed one user's posts to another. Everything on the page is a few lines of skapi-js and nothing else. It needs a logged-in user.
You need your project ID to open the demo.

database.html. The form uploads a post with its photo; the Posts section lists them four at a time.

Posting. The chosen photo is previewed before the upload; postRecord() takes the form as it is, file included, and shows the upload progress on the button.

The posts, newest first. The heading names the view that is showing, and the links beside it switch between the views. Each post is one record: the photo from its file, the description and tags from its data, the uploader looked up once with getUsers(). A guest signed in with anonymousLogin() shows as Guest; everyone else shows their name, or their public email address when they have no name.

A post after a like and two comments. The like is a record referencing the post, the comments are records on the index comment.<record_id>, and their counts come from the reference count and the index.

Most liked: the posts ordered by the reserved index $referenced_count, the number of records referencing them.

My private posts: the same query in the access group private. Nobody else can fetch these records.

The feed after subscribing to an uploader: their posts, fetched with getFeed().

A tag view: clicking a tag under a post fetches every post carrying it.
What it demonstrates
| Feature | How the page does it |
|---|---|
| Uploading a post with a file | postRecord() with the form's file input, the description and the tags, in the table posts. The upload progress is shown on the button. See Handling Files. |
| Private posts | A checked "Private" box uploads the post to the access group private, so only its uploader can read it. See Access Restrictions. |
| Listing posts | getRecords() four at a time, newest first, with the fetchMore option behind the "Fetch more posts" button. |
| Most liked | A like is a record in the table likes that references the post, and the post was uploaded with prevent_multiple_referencing, so each user can like it once. The reference count orders the "Most liked" view through the reserved index $referenced_count. See Referencing. |
| Comments and "Most commented" | A comment is a record in the table comments with the compound index name comment.<record_id>, and getIndexes() lists those index names ordered by their totals. |
| My posts, tags | The reserved index $user_id fetches the user's own posts, and a tag in the query fetches the posts with that tag. See Tags. |
| Subscriptions and the feed | Subscribing to an uploader with subscribe() puts their posts in the user's feed, fetched with getFeed(). |
| Deleting a post | deleteRecords() on the user's own posts. |
| Who posted | getUsers() fetches the uploader's and each commenter's profile, cached so every user is fetched once. |
The view is chosen with the URL hash (#mostliked, #mostcomment, #myposts, #myprivate, #feed, #tag=<tag>), so each way of querying is a few lines in one function, and the section heading names the view that is showing.
Download
The page is part of the full template: skapi-templates.zip. See Full Examples for how to run it.
