I am using SQLite adapter for pouchdb recently, and I have issue with querying the database. Seems that "key" option for the query function does not work(returns null), and even using "startkey" excludes the startkey itself.
Here is the JavaScript code :
var keyShipment= 'aec0ba08-debd-40b1-a023-d75cc360c3af,shipment';
_localdb.query(_v_getByFromRefDocAndType,
{
key: keyShipment,
include_docs: true
});
Has anybody faced a similar issue?
Related
I am trying to pass a object { key:value} and send it to meteor publish so i can query to database.
My Mongo db database has (relevant datas only) for products:
products : {
categs:['Ladies Top','Gents'],
name : Apple
}
In meteor Publish i have the following:
Meteor.publish('product', (query) =>{
return Clothings.find(query);
})
In client i use the following to subscribe:
let query = {categs:'/ladies top/i'}; // please notice the case is lower
let subscribe = Meteor.subscribe('product',query);
if (subscribe.ready()){
clothings = Products.find(query).fetch().reverse();
let count = Products.find(query).fetch().reverse().length; // just for test
}
The issue is, when i send the query from client to server, it is automatically encoded eg:
{categs:'/ladies%top/i'}
This query doesnot seem to work at all. There are like total of more than 20,000 products and fetching all is not an option. So i am trying to fetch based on the category (roughly around 100 products each).
I am new to ,meteor and mongo db and was trying to follow existing code, however this doesnot seem to be correct. Is there a better way to improve the code and achieve the same ?
Any suggestion or idea is highly appreciated.
I did go through meteor docs but they dont seem to have examples for my scenario so i hope someone out there can help me :) Cheers !
Firstly, you are trying to send a regex as a parameter. That's why it's being encoded. Meteor doesn't know how to pass functions or regexes as parameters afaict.
For this specific publication, I recommend sending over the string you want to search for and building the regex on the server:
client:
let categorySearch = 'ladies top';
let obj = { categorySearch }; // and any other things you want to query on.
Meteor.subscribe('productCategory',obj);
server:
Meteor.publish('productCategory',function(obj){
check(obj,Object);
let query = {};
if (obj.categorySearch) query.category = { $regex: `/${obj.categorySearch}/i` };
// add any other search parameters to the query object here
return Products.find(query);
});
Secondly, sending an entire query objet to a publication (or Method) is not at all secure since an attacker can then send any query. Perhaps it doesn't matter with your Products collection.
I have a mobile app written using Apache Cordova. I am using Azure Mobile Apps to store some data.
I created Easy Tables and 1 Easy API. The purpose of the API is to perform delete / update more than 1 record. Below is the implementation of the API.
exports.post = function (request, response){
var mssql = request.service.mssql;
var sql = "delete from cust where deptno in ( ? )";
mssql.query(sql, [request.parameters],{
success : function(result){ response.send(statusCodes.OK, result); },
error: function(err) { response.send(statusCodes.BAD_REQUEST, { message: err}); }
});
}
Is there any other way to implement it ? The del() method on table object on takes id to delete and I didn't find any other approach to delete multiple rows in the table.
I am having difficulty to test the implementation as the changes in the API code is taking 2-3 hours on average to get deployed. I change the code through Azure website and when I run it, the old code is hit and not the latest changes.
Is there any limitation based on the plans we choose?
Update
The updated code worked.
var sql = "delete from trollsconfig where id in (" + request.body.id + ")";
mssql.query(sql, [request.parameters],{
success : function(result){ response.send(statusCodes.OK, result); },
error: function(err) { response.send(statusCodes.BAD_REQUEST, { message: err}); }
});
Let me cover the last one first. You can always restart your service to use the latest code. The code is probably there but the Easy API change is not noticing it. Once your site "times out" and goes to sleep, the code gets reloaded as normal. Logging onto the Azure Portal, selecting your site and clicking Restart should solve the problem.
As to the first problem - there are a variety of ways to implement deletion, but you've pretty much got a good implementation there. I've not run it to test it, but it seems reasonable. What don't you like about it?
I am new to firebase and I am having a bit of a nightmare trying to adapt old code to what is now deprecated and what is not. I am trying to write a function which updates one "single" record in my datasource using the now approved $save()promise but it is doing some really strange stuff to my data source.
My function (should) enables you to modify a single record then update the posts json array. However, instead of doing this, it deletes the whole datasource on the firebase server and it is lucky that I am only working with testdata at this point because everything would be gone.
$scope.update = function() {
var fb = new Firebase("https://mysource.firebaseio.com/Articles/" + $scope.postToUpdate.$id);
var article = $firebaseObject(ref);
article.$save({
Title: $scope.postToUpdate.Title,
Body: $scope.postToUpdate.Body
}).then(function(ref) {
$('#editModal').modal('hide');
console.log($scope.postToUpdate);
}, function(error) {
console.log("Error:", error);
});
}
Funnily enough I then get a warning in the console "after" I click the button:
Storing data using array indices in Firebase can result in unexpected behavior. See https://www.firebase.com/docs/web/guide/understanding-data.html#section-arrays-in-firebase for more information. Also note that you probably wanted $firebaseArray and not $firebaseObject.
(No shit?) I am assuming here that $save() is not the right call, so what is the equivalent of $routeParams/$firebase $update()to do a simple binding of the modified data and my source? I have been spending hours on this and really don't know what is the right solution.
Unless there's additional code that you've left out, your article $firebaseObject should most likely use the fb variable you created just before it.
var article = $firebaseObject(fb);
Additionally, the way in which you're using $save() is incorrect. You need to modify the properties on the $firebaseObject directly and then call $save() with no arguments. See the docs for more.
article.Title = $scope.postToUpdate.Title;
article.Body = $scope.postToUpdate.Body;
article.$save().then(...
I'm using oracle adapter, async.each and findOrCreate to transfer some data from oracle to my postgres db:
//simplified version
oracle.select(sql, [], function(err, results) {
async.each(results, function(add_me, async_cb){
model_to_add.findOrCreate(
{not_id_field: add_me.value},
{required_fields: add_me.values}
).exec(function add_me_cb(err, record){
if (record && !err){
async_cb();
}
});
});
})
My sql query returns multiple, not unique values for not_id_field. But I want it to be unique in my postgres db. I thought finOrCreate is the great thing to use. But it somehow fails to find a record.
Was I wrong? Or maybe there's something I'm missing? sails.js documentation isn't really helpful : (
Turns out it was a problem with me - I didn't really understand how async.each works and that it is executed for every item in the array almost at the same time. I switched to async.eachSeries and now it works fine.
I am using QtQuick/QML/Qt5.2.1 on Android. I also tested this issue on the Desktop rather than Android and I see the same problem.
I use LocalStorage to persist application data after the application closes.
I open a database using openDatabaseSync:
var db = LocalStorage.openDatabaseSync(
"TestDB",
"1.0", <-- version
"Test Database",
1000000,
function(db) {
createSchema(db);
populateData(db);
}
);
If the database does not exist and was created, the callback function gets executed and in that case I create the database schema and populate the initial dataset.
The next time the application starts, obviously I want to keep the database as-is and not recreate it.
The problem is when I restart the application I get this error:
Error: SQL: database version mismatch
If I inspect the .ini file that was created when the database was created the first time the application was run, I see this:
[General]
Description=Test Database
Driver=QSQLITE
EstimatedSize=1000000
Name=TestDB
Version=
You can clearly see a problem here is that the "Version" attribute is empty.
When the application starts up, it compares the requested version "1.0" against this empty string "" and fails.
I can fake it to get it to work of course by specifying the version as "", or by fixing the ini file - that at least tells me the code is otherwise correct - but clearly that's not a solution.
So, did I miss something or is this a Qt bug?
You can set the database version after creating it:
var db = LocalStorage.openDatabaseSync(
"TestDB",
"1.0",
"Test Database",
1000000,
function(db) {
createSchema(db);
populateData(db);
db.changeVersion("", "1.0");
}
);
Since the callback function will only be called it the database doesn't exists, and the changeVersion function will only work if current version is "" (otherwise, exception is thrown), I believe it's safe to use it.
EDIT: Maybe this is the intended behaviour... from LocalStorage source code, line 700:
if (dbcreationCallback)
version = QString();
So, maybe you really need to set db version after you create your tables... before you do that on the callback, it's just an empty database, and shouldn't really have a version.
set the attributes like this in your above code
// db = LocalStorage.openDatabaseSync(identifier, version, description, estimated_size, callback(db))
LocalStorage.openDatabaseSync("kMusicplay", "0.1", "kMusicPlay app Ubuntu", 10000);
where
'kMusicplay' is appname ,
'0.1' is version ,
'kMusicPlay app Ubuntu' is app discription
and '10000' is size of database