### Installing Dependencies for Testing Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Testing.md This command installs the necessary dependencies for running dstore tests. It should be executed from the dstore directory. ```bash npm install ``` -------------------------------- ### Database Configuration Object Example Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This example demonstrates the structure of a database configuration object for dstore/LocalDB. It defines the database version, stores (posts and comments), and properties with indexing preferences, including auto-incrementing, multi-entry, and disabling indexing. ```JavaScript var dbConfig = { version: 5, stores: { posts: { name: 10, id: { autoIncrement: true, preference: 100 }, tags: { multiEntry: true, preference: 5 }, content: { indexed: false } }, commments: { author: {}, content: { indexed: false } } } }; ``` -------------------------------- ### Creating a Trackable Memory Store Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example demonstrates how to create a trackable memory store by mixing in `dstore/Trackable` with `dstore/Memory` using `declare`. ```javascript var TrackableMemory = declare([Memory, Trackable]); ``` -------------------------------- ### Initializing LocalDB Stores Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This example shows how to initialize LocalDB stores with a database configuration object and a store name. Each store instance is associated with a specific store defined in the database configuration. ```JavaScript var postsStore = new LocalDB({ dbConfig: dbConfig, storeName: 'posts' }); var commentsStore = new LocalDB({ dbConfig: dbConfig, storeName: 'comments' }); ``` -------------------------------- ### Fetching Data in a Tracked Collection Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example demonstrates how to fetch all items in a tracked collection using `fetch()`. ```javascript tracked.fetch(); ``` -------------------------------- ### Tracking a Filtered and Sorted Collection Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example shows how to create a new instance from a trackable memory store, filter and sort the store, and then track the resulting collection using the `track()` method. ```javascript var store = new TrackableMemory({ data: [...] }); var filteredSorted = store.filter({ inStock: true }).sort('price'); var tracked = filteredSorted.track(); ``` -------------------------------- ### Creating a Trackable Rest Store with SimpleQuery Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example demonstrates how to create a trackable REST store by mixing in `dstore/Trackable` and `dstore/SimpleQuery` with `dstore/Rest` using `declare`. This is necessary when using server-side stores to provide client-side querying functionality. ```javascript var TrackableRest = declare([Rest, SimpleQuery, Trackable]); ``` -------------------------------- ### Checking the current branch Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md This command displays the current branch. It is useful for verifying that you are on the correct branch before making changes. ```sh $ git status # On branch t12345 nothing to commit, working directory clean ``` -------------------------------- ### Fetching a Range of Data in a Tracked Collection Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example demonstrates how to fetch a specific range of items in a tracked collection using `fetchRange()`. ```javascript tracked.fetchRange(0, 10); ``` -------------------------------- ### Pushing changes to origin Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md This command pushes the current branch to the remote repository (origin). The -u option sets up the local branch to track the newly-created branch on the remote. ```sh $ git push -u origin t12345 ``` -------------------------------- ### Creating a new branch Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md This command creates a new branch based on the master branch. The branch name should be descriptive and can include the issue number being addressed. ```sh $ git checkout -b fix-123-short-description master Switched to a new branch 'fix-123-short-description' ``` -------------------------------- ### Committing changes Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md This command commits the staged changes to the local repository with a descriptive message. The message should include the issue number being addressed. ```sh $ git status # On branch t12345 # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: somefile.js # $ git commit -m 'Corrects some defect, fixes #123' [t12345 0000000] Corrects some defect, fixes #123 1 file changed, 2 insertions(+), 2 deletions(-) ``` -------------------------------- ### Pushing changes after initial push Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md This command pushes the current branch to the remote repository (origin). It assumes that the local branch is already tracking a remote branch. ```sh $ git push ``` -------------------------------- ### Listening for Notifications on a Tracked Collection Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example demonstrates how to listen for 'add', 'update', and 'delete' events on a tracked collection and access the event properties such as `index`, `previousIndex`, and `target`. ```javascript tracked.on('add, update, delete', function (event) { var newIndex = event.index; var oldIndex = event.previousIndex; var object = event.target; }); ``` -------------------------------- ### Cloning a Forked Repository Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md Clones the forked dstore repository from GitHub to your local machine. Replace 'username' with your GitHub username. This command creates a local copy of your forked repository in a directory named 'dstore'. ```sh $ git clone git@github.com:username/dstore.git ``` -------------------------------- ### Setting Up Upstream Remote Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md Adds a remote named 'upstream' that points to the official dstore repository. This allows you to fetch changes from the official repository and merge them into your local clone. The 'git fetch upstream' command retrieves the latest changes from the upstream repository. ```sh $ cd dstore $ git remote add upstream https://github.com/SitePen/dstore.git $ git fetch upstream ``` -------------------------------- ### Synchronous Get Operation Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Store.md Retrieves an object by its identity synchronously. Returns the object if found, otherwise returns undefined. ```JavaScript getSync(id) ``` -------------------------------- ### Rebasing with upstream master Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md This command rebases the current branch on top of the latest changes from the upstream master branch. This ensures that the pull request can be applied cleanly. ```sh $ git pull --rebase upstream master ``` -------------------------------- ### Creating a Custom Query Method Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This example demonstrates how to create a custom query method called `getChildren` using the `dstore/QueryMethod` module. The method queries for children objects by returning the children property array from a parent. ```javascript declare([Memory], { getChildren: new QueryMethod({ type: 'children', querierFactory: function (parent) { var parentId = this.getIdentity(parent); return function (data) { // note: in this case, the input data is ignored as this querier // returns an object's array of children instead // return the children of the parent // or an empty array if the parent no longer exists var parent = this.getSync(parentId); return parent ? parent.children : []; }; } }) }); ``` -------------------------------- ### Sorting a collection with multiple sort orders Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md Demonstrates how to sort a dstore collection using multiple sort orders. The example sorts by 'lastName' first, then by 'firstName' for identical 'lastName' values. ```JavaScript collection.sort([ { property: 'lastName' }, { property: 'firstName' } ]) ``` -------------------------------- ### Filtering with nested property query Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md Demonstrates how to filter a dstore using a nested property query. This example filters for objects where the 'name.last' property is equal to 'Smith'. ```JavaScript store.filter({ 'name.last': 'Smith' }) ``` -------------------------------- ### Selecting a single property from a collection Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md Shows how to select a single property from a dstore collection. This example selects the 'name' property from each object in the collection, returning a collection of name values. ```JavaScript collection.select('name'); ``` -------------------------------- ### Object matching nested property query Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md Shows an example of an object that would match the nested property query in the previous snippet. The object has a 'name' property, which is an object containing 'first' and 'last' name properties. ```JavaScript { name: { first: 'John', last: 'Smith' } } ``` -------------------------------- ### Rebasing with Upstream Changes Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/CONTRIBUTING.md Retrieves the latest changes from the upstream repository and rebases your local branch on top of them. This helps keep your fork up-to-date with the official repository and avoids merge conflicts. It assumes that you are on the branch you want to rebase. ```sh $ git pull --rebase upstream master ``` -------------------------------- ### Running Tests via Sauce Labs Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Testing.md This command runs the dstore tests using Sauce Labs. It specifies the configuration file to use for the test run. ```bash node node_modules/intern-geezer/runner config=tests/intern ``` -------------------------------- ### Initializing a Rest Store Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md Demonstrates how to initialize a Rest store with a target URL. The target URL specifies the endpoint for data retrieval and modification. ```JavaScript myStore = new Rest({ target: '/PathToData/' }); ``` -------------------------------- ### Initializing a Memory Store with Data in JavaScript Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This code demonstrates how to create a Memory store instance with initial data provided in the `data` property of the constructor. The data should be an array of objects, each with a unique identity. ```JavaScript myStore = new Memory({ data: [{ id: 1, aProperty: ..., ... }] }); ``` -------------------------------- ### Setting Sauce Labs Credentials Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Testing.md These commands set the Sauce Labs username and access key as environment variables. These credentials are required to run tests via Sauce Labs. ```bash export SAUCE_USERNAME= export SAUCE_ACCESS_KEY= ``` -------------------------------- ### Running Tests in the Console Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Testing.md This command runs the dstore tests in the console using Intern. It specifies the configuration file to use for the test run. ```bash node node_modules/intern-geezer/client config=tests/intern ``` -------------------------------- ### Initializing Cache with Existing Store Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This code snippet demonstrates how to create a cached store using the Cache.create method, wrapping an existing store and providing a Memory store for caching. ```JavaScript var cachedStore = Cache.create(existingStore, { cachingStore: new Memory() }); ``` -------------------------------- ### Enabling RQL Querying in dstore Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This code snippet demonstrates how to enable RQL querying in dstore by mixing in the `RqlQuery` extension. It creates a new store `RqlStore` that inherits from `Memory` and `RqlQuery`. It then filters the store using an RQL query string. ```JavaScript require([ 'dojo/_base/declare', 'dstore/Memory', 'dstore/extensions/RqlQuery' ], function (declare, Memory, RqlQuery) { var RqlStore = declare([ Memory, RqlQuery ]); var rqlStore = new RqlStore({ ... }); rqlStore.filter('price<10|rating>3').forEach(function (product) { // return each product that has a price less than 10 or a rating greater than 3 }); }}; ``` -------------------------------- ### Combining Rest, SimpleQuery, and Trackable Stores in JavaScript Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This code demonstrates how to create a custom store class by combining the Rest, SimpleQuery, and Trackable stores using `dojo declare`. This is useful for adding tracking to the `dstore/Rest` store, which requires client-side querying provided by `dstore/SimpleQuery`. ```JavaScript var TrackedRestStore = declare([Rest, SimpleQuery, Trackable]); ``` -------------------------------- ### Combining Memory Store with Trackable and Tree Mixins in JavaScript Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This code demonstrates how to create a custom store class by combining the Memory store with the Trackable and Tree mixins using `dojo declare`. It then instantiates the new class with sample data. ```JavaScript // create the class based on the Memory store with added functionality var TrackedTreeMemoryStore = declare([Memory, Trackable, Tree]); // now create an instance var myStore = new TrackedTreeMemoryStore({ data: [...] }); ``` -------------------------------- ### Adapting dstore to Legacy Dojo Object Store Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Adapters.md The `DstoreAdapter` module allows a dstore store to be used as a legacy Dojo object store. It adapts an existing dstore (e.g., `dstore/Memory`) to a legacy Dojo object store, enabling it to be used with Dojo components that expect the legacy store interface. If the dstore is trackable, result sets from `query()` will be observable. ```JavaScript require([ 'dstore/legacy/DstoreAdapter', 'dstore/Memory' ], function(DstoreAdapter, Memory) { var store = new Memory({...}); var adaptedStore = new DstoreAdapter(store); }); ``` -------------------------------- ### Combining Rest and RequestMemory Stores in JavaScript Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md This code demonstrates how to create a custom store class by combining the Rest and RequestMemory stores using `dojo declare`. It then instantiates the new class with a target URL for data retrieval and modification. ```JavaScript var RestMemoryStore = declare([Rest, RequestMemory]); // now create an instance var myStore = new RestMemoryStore({ target: '/data-source/' }); ``` -------------------------------- ### Adapting Dojo Object Store to dstore Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Adapters.md The `StoreAdapter` module allows a Dojo object store to be used as a dstore store. It adapts an existing `dojo/store/Memory` object store to a dstore, enabling it to be used with dstore components. The adapted store provides all methods and properties inherited from `dstore/api/Store`. ```JavaScript require([ 'dstore/legacy/StoreAdapter', 'dojo/store/Memory' ], function(StoreAdapter) { var objectStore = new Memory({...}); var adaptedStore = new StoreAdapter({objectStore: objectStore}); }); ``` -------------------------------- ### Using dstore with Dojox Charting Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Adapters.md The `StoreSeries` module allows a dstore object to be used as a `Series` in a Dojox chart. It adapts a dstore to be used as a data series in a Dojox chart. The constructor expects a dstore object store and an optional value parameter to specify the property to extract from each store item. ```JavaScript require([ 'dstore/charting/StoreSeries' ], function (StoreSeries) { //... create a store and a chart ... // Adds a StoreSeries to the y axis. chart.addSeries('y', new StoreSeries(store)); }); ``` -------------------------------- ### Creating a Filter Object Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This code snippet shows how to create a new filter object from the `Filter` constructor on a store. This filter object can then be used to build more sophisticated filter conditions. ```JavaScript var filter = new store.Filter(); ``` -------------------------------- ### Synchronous Add Operation Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Store.md Creates an object synchronously, throwing an error if the object already exists. Returns the newly created object. ```JavaScript addSync(object, [directives]) ``` -------------------------------- ### Applying a Filter to a Store Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This code snippet shows how to apply a filter object to a store using the `filter()` method. It creates a new collection containing only the objects that match the filter conditions. ```JavaScript var highPriorityFiveStarCollection = store.filter(highPriorityFiveStarFilter); ``` -------------------------------- ### Building a Filter with Multiple Conditions Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This code snippet demonstrates how to build a filter with multiple conditions using the `eq()` and `gt()` methods. It creates a filter that matches objects with a `priority` of 'high' and a `stars` value greater than 5. ```JavaScript var highPriorityFiveStarFilter = filter.eq('priority', 'high').gt('stars', 5); ``` -------------------------------- ### Server Response Format for Request/Rest Store Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Stores.md Describes the expected JSON format for server responses when using Request or Rest stores. The response should include a 'data' array (or an object with an 'items' array) and a 'total' property indicating the total number of items. ```JSON { "total": 500, "items": [ /* ...items */ ] } ``` -------------------------------- ### Querying a Store with Filter and Sort Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This code snippet demonstrates how to query a store using the `filter()` and `sort()` methods. It filters the store for objects with a `priority` of 'high' and then sorts the results by the `dueDate` property. The `forEach()` method is then used to iterate over the filtered and sorted results. ```JavaScript store.filter({priority: 'high'}).sort('dueDate').forEach(function (object) { // called for each item in the final result set }); ``` -------------------------------- ### Nested Query with Filter and Select Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Collection.md This code snippet demonstrates how to perform a nested query using the `in` filter and the `select` method. It finds all tasks in high priority projects by filtering the `taskStore` based on the `projectId` property, which references objects in the `projectStore`. ```JavaScript var tasksOfHighPriorityProjects = taskStore.filter( new Filter().in('projectId', projectStore.filter({ priority: 'high' }).select('id') ) ); ``` -------------------------------- ### Synchronous Put Operation Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Store.md Stores an object synchronously, either updating an existing object or creating a new one. Returns the object after it has been saved. ```JavaScript putSync(object, [directives]) ``` -------------------------------- ### Synchronous Remove Operation Source: https://github.com/dojo/dojo1-dstore/blob/master/docs/Store.md Deletes an object synchronously, using the identity to indicate which object to delete. Returns a boolean value indicating whether the object was successfully removed. ```JavaScript removeSync(id) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.