Skip to content

Instantly share code, notes, and snippets.

// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Sprout Systems, Inc. and contributors.
// Portions ©2008-2009 Apple, Inc. All rights reserved.
// License: Licened under MIT license (see license.js)
// ==========================================================================
require('core') ;
/**
@class
thomaslang: hi okito, are you there?
[17:50] okito: hey thomaslang
[17:51] thomaslang: I just pushed a new version of thomaslang/query -- reworked fetchRecords a little bit
[17:52] thomaslang: now it accepts this: s.findAll("name = 'b' OR count = %@",{wildCardValues:[2]})
[17:52] thomaslang: or this: s.findAll("name MATCHES %@",{wildCardValues:[/a/]})
[17:53] thomaslang: matching with regexps was added lately
[17:53] thomaslang: s is your store
[17:53] okito: sweet
[17:53] okito: !
[17:54] thomaslang: some problems there are however
thomaslang: so the idea is to allow you to write custom query-methods on your dataSource, like 'recentContacts'
[11:09] thomaslang: you could call it with yourStore.findAll('recentContacts')
[11:09] geoffreyd: yup, much like a named view
[11:09] geoffreyd: I like it
[11:10] geoffreyd: could you add extra filters onto it?
[11:10] thomaslang: you mean like chained named scopes in rails?
[11:10] sudara: oooh
[11:11] sudara: that sounds tasty.
[11:11] thomaslang: i would like to do it - but i am still not sure how to
[11:11] geoffreyd: umm, that's a neat idea, but I was thinking: if you had a 'recentContacts' search, could I then pass in another filter, like sex = 'f'
// test
test("should handle record types", function() {
q.queryString = "TYPE_IS 'MyApp.Foo'";
q.parseQuery();
ok(q.parseQuery(), 'query should parse'); // passes
equals(q.tokenList[0].tokenType, 'COMPARATOR', 'token should be comparator'); // passes
ok(SC.Store.recordTypeFor(rec1.storeKey).toString() == 'MyApp.Foo', 'record type as string should be MyApp.Foo'); // fails
// this is a property of SC.Query:
compareObjects: function (v1, v2) {
var orderDefinition = ['null','boolean','number','string','array','object'];
getType = function (v) {
var t = typeof v;
if (t == 'object') {
if (t == null) return 'null';
if (t instanceof Array) return 'array';
compareObjects: function (v1, v2) {
var orderDefinition = [SC.T_ERROR, SC.T_UNDEFINED, SC.T_NULL, SC.T_BOOL, SC.T_NUMBER, SC.T_STRING, SC.T_ARRAY, SC.T_HASH, SC.T_OBJECT, SC.T_FUNCTION, SC.T_CLASS];
//function getType (v) {
// var t = typeof v;
// if (t == 'object') {
// if (t == null) return 'null';
// if (t instanceof Array) return 'array';
// }
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Apple, Inc. and contributors.
// License: Licened under MIT license (see license.js)
// ==========================================================================
/*globals module ok equals same test MyApp */
// test parsing of query string
var store, storeKey, rec1, rec2, rec3, rec4, rec5, MyApp, q;
module("SC.Query comparison/ordering of records", {
compareObjects: function (v1, v2) {
var orderDefinition = [SC.T_ERROR, SC.T_UNDEFINED, SC.T_NULL, SC.T_BOOL, SC.T_NUMBER, SC.T_STRING, SC.T_ARRAY, SC.T_HASH, SC.T_OBJECT, SC.T_FUNCTION, SC.T_CLASS];
var type1 = SC.typeOf(v1);
var type2 = SC.typeOf(v2);
if (orderDefinition.indexOf(type1) < orderDefinition.indexOf(type2)) return -1;
if (orderDefinition.indexOf(type1) > orderDefinition.indexOf(type2)) return 1;
// ==========================================================================
// Project: SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Apple, Inc. and contributors.
// License: Licened under MIT license (see license.js)
// ==========================================================================
/*globals module ok equals same test MyApp */
// test parsing of query string
var v = [], q, c;
module("SC.Query ordering", {
8 should equal itself, expected: 0 result: undefined FAILED
8 should be smaller than 9, expected: -1 result: undefined FAILED
9 should equal itself, expected: 0 result: undefined FAILED
10 should equal itself, expected: 0 result: undefined FAILED