How to fetch data from ydn-db with multiple conditions - ydn-db

I am developing an web app. Therefore I use Sencha Touch 2 and for ydn db for local storage.
My question is, how can I fetch data from ydn db by 2 or more conditions? For example username=Moo and street = Teststreet and lastname = 'xy'?
Thanks for replies. :-)

Here's I how do it using scan() but hopefully .where().where() will be implemented soon.
var iters, key_range, result, solver;
iters = [];
key_range = ydn.db.KeyRange.only(18);
iters.push(new ydn.db.IndexIterator('person', 'age', key_range));
key_range = ydn.db.KeyRange.only('F');
iters.push(new ydn.db.IndexIterator('person', 'sex', key_range));
result = [];
solver = new ydn.db.algo.NestedLoop(result);
db.scan(solver, iters).then(function() {
console.log(result);
});
I based this example from here https://github.com/yathit/ydn-db/blob/master/test/qunit/cursor.js#L929-L943
Hope that helps.

Read this doc. Currently it is not easy.

Related

How to async join tables in RavenDB

I need to do query from two raven db tables.
I found almoust perfect solution in documentation, only problem is im using async session and have no idea what is async equivalent.
var q = from order in dq
let company = session.Load<Company>(order.Company)
select new
{
order.Freight,
company.Name
};
The correct syntax is:
RavenQuery.Load<Company>(order.Company)
https://ravendb.net/docs/article-page/5.4/csharp/indexes/querying/projections#example-viii---projection-using-a-loaded-document

How to retrieve N levels of many-to-many relations?

I have this Data structure as this (with o/m = one to many relation):
Sites-o/m-Areas-o/m-Chapters-o/m-Sections-o/m-Topics and 5 other Data models Actions, Tools, Contacts... with a m/m relation to each 5 first models.
1 Site can have many Actions so as Areas...
Not sure if doable by Data binding, client or server script!
I wrote this server script solution but not sure if it's optimal as it's already slow with 2 levels!
function calculActions(kt) {
var kn = app.models.Sites.getRecord(kt.toString());
var knac = kn.Actions;
kn.Areas.forEach(function(item){
var knarac = item.Actions;
if (knarac.length>0){
knarac.forEach(function(ac){
knac.push(ac);
});
}
var knarch = item.Chapters;
knarch.forEach(function(item){
var knarchac = item.Actions;
if (knarchac.length>0){
knarchac.forEach(function(ac){
knac.push(ac);
});
}
});
});
return knac;
}
The goal is to displayed a tab for each asset (Actions, Tools, Notes...) associated to a same Site.
I'm sure there's a clean and efficient version of my draft!
Thx in advance for any help, I need to sleep :-)

Firebase function access not related data [duplicate]

This question already has an answer here:
How to read any data from database on its write trigger on one of its child in firebase functions?
(1 answer)
Closed 5 years ago.
I'm searching for a way when I can access database elements not related to my trigger data in firebase functions.
As I see I can set(...) things on other elements but unfortunately I can't just read the values out of the elements, for example this doesn't work:
event.data.adminRef.root.child('bettings/'+matchId+'/begin_at').val()
I know about the 'proper way' to get those things, which is like:
var match = event.data.adminRef.root.child('bettings/' + matchId + '/begin_at');
match.once('value',function(snapshot){
var alma = snapshot.val();
console.log('alma val');
console.log(alma);
});
But I hope there is a better/easier way then write such codes all the time I need something out of my current scope.
Update: it is not a duplicate of How to read any data from database on its write trigger on one of its child in firebase functions? !
I know about ....once(..), and that I can access the values through promises but I need a much more quicker way, because sometimes it takes about 10 seconds, which is really slow and the user won't get the response in time!
Here is an example where you access data from a specific database node and perform a task with the value jobowner:
let jobRef = admin.database().ref(`/jobs/${jobid}`);
const jo = jobRef.child("owner").once('value');
return Promise.all([jo]).then(r => {
const jobowner = r[0];
const promises = [];
let key = admin.database().ref(`/jobowners/${jobowner}`).set({
value: 'test',
other: false
});
promises.push(room);
return Promise.all(promises);
});

Deleting data from Drive Tables and automatically re-importing new data

I need help with trying to understand how to delete all data from a table and then try to automatically import a new sheet with data into the newly cleared down table.
I'm currently trying the unload() method client side but that doesn't seem to cleardown my tables
function ClearDown(){
app.datasources.P11d.unload(function(){});
console.log('Finish Delete');
}
I've also tried to create a server side function, which also doesn't appear to work
function ClearTable(){
var records = app.models.P11d.newQuery();
// records.run();
console.log('Server Function Ran');
app.deleteRecords(records.run());
}
This is ran from a client side function:
function Delete(){
google.script.run.withSuccessHandler(function(result){
}).ClearTable();
console.log('Function Ran');
}
Again this is all to no avail
With the import side I've tried to do the below:-
Client Side:
function ImportData(){
console.log('Begin');
var ss = SpreadsheetApp.openById('SHEET ID');
var values = ss.getSheetByName('P11d').getDataRange().getValues();
var ssData = [];
// app.datasources.P11d.unload(function(){});
for (var i = 0; i<values.length; i++){
var newRecord = app.models.P11d.newRecord();
// add all fields to the new record
newRecord.Reg_Number = values[i][0];
newRecord.Reg_Date = values[i][1];
newRecord.Model_Description = values[i][2];
newRecord.P11d_Value = values[i][3];
newRecord.EngineSize = values[i][4];
newRecord.Fuel = values[i][5];
newRecord.CO2 = values[i][6];
newRecord.SIPP = values[i][7];
newRecord.GTA_Code = values[i][8];
newRecord.Type = values[i][9];
ssData.push(newRecord);
// console.log(newRecord.MODEL_FIELD);
}
console.log('Finished');
// return the array of the model.newRecord objects that would be consumed by the Model query.
}
Please can someone help with this, at the moment the way the data is sent over to me adding new stuff into the Drive Table is causing many duplicates.
Thanks in advance,
You can delete all records, import, and read from a spreadsheet using the AMU Library
Copy and paste the server and client scripts into your app.
I'm sure that will make it much easier!
To delete all the data in a model using this:
Button onClick:
google.script.run.AMU.deleteAllData('ModelName');
The correct way to delete records on the server is:
app.models.MODEL_NAME.deleteRecords(key_array);
datasource.unload() simply unloads the widget on the client. It does not affect the database records.
A better way to write your records query on the server is:
var query = app.models.MODEL_NAME.newQuery();
query.filters.your_filter_here;
var records = query.run();
Note that you cannot return a single record or an array of records from anything but a calculated model function without using a function posted here. (You can return a single field of a record using stringify for any json data.)
I am currently working on a solution to create datasource independent tables needed in App Maker.
For the delete function on the server try to change your code just a little bit, this function at least used to work for me, however I have not needed to use it in some time.
function ClearTable(){
var records = app.models.P11d.newQuery().run();
console.log('Server Function Ran');
app.deleteRecords(records);
}

data not set using .set on Firebase

First question here,
I am trying to follow the startup guide on the Firebase, but as I am trying to click the send button, the data is not transferred to the data server.
Here is the code:
var yjDataRef = new Firebase('https://yjyc-signup.firebaseio.com/');
var name = document.getElementById('name');
var email = document.getElementById('email');
var submitBtn = document.getElementById('submit');
nameRef = yjDataRef.child('nameRef');
submitBtn.addEventListener('click' function() {
nameRef.set(name: 'name');
});
I have called all of them but still, the data does not transferred to the data center.
Thank you so much for your help.
I believe you need a comma after 'click'.
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Resources