Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Adds limit & offset. Changes dataType to json on query request #38

Merged
merged 2 commits into from
Nov 5, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions js/maps_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,43 @@ var MapsLib = {
MapsLib.searchRadiusCircle = new google.maps.Circle(circleOptions);
},

query: function(selectColumns, whereClause, groupBy, orderBy, callback) {
query: function(query_opts, callback) {

var queryStr = [];
queryStr.push("SELECT " + selectColumns);
queryStr.push("SELECT " + query_opts.select);
queryStr.push(" FROM " + MapsLib.fusionTableId);

// where, group and order clauses are optional
if (whereClause != "" && whereClause != null)
queryStr.push(" WHERE " + whereClause);

if (groupBy != "" && groupBy != null)
queryStr.push(" GROUP BY " + groupBy);
if (query_opts.where && query_opts.where != "") {
queryStr.push(" WHERE " + query_opts.where);
}

if (query_opts.groupBy && query_opts.roupBy != "") {
queryStr.push(" GROUP BY " + query_opts.groupBy);
}

if (query_opts.orderBy && query_opts.orderBy != "" ) {
queryStr.push(" ORDER BY " + query_opts.orderBy);
}

if (query_opts.offset && query_opts.offset !== "") {
queryStr.push(" OFFSET " + query_opts.offset);
}

if (query_opts.limit && query_opts.limit !== "") {
queryStr.push(" LIMIT " + query_opts.limit);
}

if (orderBy != "" && orderBy != null)
queryStr.push(" ORDER BY " + orderBy);


var sql = encodeURIComponent(queryStr.join(" "));
$.ajax({url: "https://www.googleapis.com/fusiontables/v1/query?sql="+sql+"&callback="+callback+"&key="+MapsLib.googleApiKey, dataType: "jsonp"});
$.ajax({
url: "https://www.googleapis.com/fusiontables/v1/query?sql="+sql+"&key="+MapsLib.googleApiKey,
dataType: "json"
}).done(function (response) {
if (callback) callback(response);
});

},

handleError: function(json) {
Expand All @@ -249,7 +269,12 @@ var MapsLib = {

getCount: function(whereClause) {
var selectColumns = "Count()";
MapsLib.query(selectColumns, whereClause, "", "", "MapsLib.displaySearchCount");
MapsLib.query({
select: selectColumns,
where: whereClause
}, function(response) {
MapsLib.displaySearchCount(response);
});
},

displaySearchCount: function(json) {
Expand Down