Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The words “local” and “remote” have nothing to do with where the data comes from – all your data probably comes from your server, and at any rate <code>SC.Query</code> doesn’t care. What the words mean is where the <em>decisions</em> are made. <strong>Local</strong> queries get fulfilled (and are updated live!) locally by SproutCore itself; <strong>remote</strong> queries rely on your server to make the decisions.</p> <p>The basic fundamental difference then is: “Can/should/does my local store have local copies of all of the records required to fulfill this request?” If yes, use a local query; if no, use a remote query.</p> <p>For example, in a document editing application, if the query is “get all of the logged-in user’s documents”, then the decision must be made by someone with access to “all documents across all users” – which the client should clearly not have, for reasons of performance and security! This should therefore be a <strong>remote</strong> query. But once all of the user’s documents are loaded locally, then another query such as “All of the user’s documents which have been edited in the last three days” can (and should) be executed <strong>locally</strong>.</p> <p>Similarly, if a query is looking across a small number of records, it makes sense for the client to load them all and search <strong>locally</strong>; if it’s a search across millions of records, which the client can’t be expected to load and search, then the <strong>remote</strong> server will have to be relied upon for fulfillment.</p> <p>The store will send <strong>both remote and local</strong> queries to your data source’s <code>fetch</code> method, where you can tell the difference via <code>query.get(‘isRemote’)</code>. But the store expects the data source to do different things in each case.</p> <p>It is your data source’s responsibility to fulfill <strong>remote</strong> queries. You’ll probably make a server call, then load records (if needed) via <code>store.loadRecords(recordTypes, hashes, *ids*)</code> (which returns an array of store keys), then use <code>store.dataSourceDidFetchQuery(query, storeKeys)</code> to fulfill the query and specify results.</p> <p>On the other hand, with <strong>local</strong> queries, the store is essentially making a courtesy call – it’s letting your data source know that this kind of information has been requested, so you can decide if you’d like to load some data from the server. The store will happily fulfill the query all by itself, whether or not the data source takes any action. If you do decide to load some data from the server, you just need to let the store know with <code>store.dataSourceDidFetchQuery(query)</code> – without the store keys this time, because the store is making its own decisions about what records satisfy the query.</p> <p>Of course, there are other ways to implement this all. SC.Store is set up (somewhat controversially) to aggressively request information from its data source, so it’s possible to run an application using nothing but local queries, or by triggering most server requests with <code>toMany</code> relationships (which run through <code>dataSource.retrieveRecord</code>). My personal favorite approach is to do all loading of data with remote queries in my application’s state chart, and then populate my controllers and relationships with nothing but local queries.</p> <p>See the <a href="http://guides.sproutcore.com/records.html" rel="nofollow">Records guide</a>, the <a href="http://docs.sproutcore.com/#doc=SC.Query" rel="nofollow">SCQL documentation</a> at the top of the <code>SC.Query</code> docs, and the <a href="http://docs.sproutcore.com/#doc=SC.Store" rel="nofollow"><code>SC.Store</code></a> / <a href="http://docs.sproutcore.com/#doc=SC.DataSource" rel="nofollow"><code>SC.DataSource</code></a> documentation for a ton more information.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload