DexieJS return NotFoundError in a nested query - dexie

I am facing an issue on DexieJS when i had a nested query. The following is the sample of my code:-
let id = 1;
let child = db.child.where({ id : result.child_id }).first( item => item ).catch( e => "NotFoundError"; );
console.log(child); // success, it shows the child item
db.parent.where({ id : id }).each( parent => {
let child = db.child.where({ id : parent.id }).first( item => item ).catch( e => "NotFoundError"; );
console.log(child); // it will show NotFoundError
});
no idea of what is happening, does nested query not working on DexieJS which i have no doubt it should work.
Please advice, thank you in advance.

Found a solution or workaround, it is working now.
await db.transaction('r', db.parent, db.child, async () => {
await db.parent.where({ id : id }).each( async parent => {
let child = db.child.where({ parent_id : parent.id }).first( result => result );
console.log(child) // *now it shows the child record
});
});
Looks like we need to use transaction to have query within a query result.
I hope this is the right way and hope this help.
Please do not hesitate to comment if this is not the right way.
Nameste.

Related

Cypress Custom Command - Break from a .each() loop and return a value to be used in further steps

I am new to Cypress [3 days :)]. I am creating a custom command which is trying to find the column index of column in a table.
I want to return the column index and store it in a variable and use it in future steps.
Here is what I have tried:
Cypress.Commands.add('get_table_column_index', (columnName) => {
cy.getIframeBody().find('table').within(() => {
cy.get('tr th[scope=col]').each((element, index) => {
let colName = element.text();
cy.log(index, colName);
if(colName == columnName)
{
cy.wrap(index).as('index');
return false;
}
});
});
});
let columnIndex = cy.get_table_column_index('ColName').get('#index');
cy.log('index' + columnIndex);
index is [object Object]
Can someone please guide me in resolving this issue?
What am I doing wrong?
I can see that wrap is returning the correct index value but I am not sure how to extract and use it.
======= Update =========
I tried this and looks like it was able to log the correct value:
let columnIndex =
cy.get_table_column_index(column_name).get('#index');
columnIndex.then(index => cy.log(index));
Now, I am trying to expand it to use the index value in the next step like this:
Cypress.Commands.add('get_text', (row_num, column_name) => {
let txt;
cy.test_index(column_name).get('#index').then(index => {
let element = cy.get('main > table').within(() => {
cy.log('${index');
cy.get('tr:nth-child(${row_num}) td:nth-child(${index})');
//txt = element.text();
cy.log(txt);
});
});
return txt;
})
I am not able to figure out how to use the value of index and row_num in cy.get('tr:nth-child(${row_num}) td:nth-child(${index})'; expression.
Error: Syntax error, unrecognized expression: :nth-child
All you need to do is change the way that you are using variable.
cy.log(this.index + columnIndex);
I was able to get this working like this:
.get('#index').then(....
was used to extract the value of the index which is returned by my method get_table_column_index.
Then used cy.wrap again to return the cell value.
Cypress.Commands.add('get_text', (row_num, column_name) => {
cy.get_table_column_index(column_name).get('#index').then(index => {
cy.get('main > table').within(() => {
cy.get(`tr:nth-child(${row_num}) td:nth-child(${index})`)
.invoke('text')
.then((text) => {
cy.log("Text = " + text);
return cy.wrap(text).as('cell_value');
})
});
});
})
Then finally in my method call:
let cell_text = cy.get_text(2, 'Licensing').get('#cell_value');
cell_text.then(cell_value => {
cy.log(cell_value);
expect(cell_value).to.include('QTP');
})
The only thing I am not able to do is to store the value in a variable and use it without chaining any command like then to extract its value.
It would be great if someone can provide more information on that.
Thanks.

How to Insert value into main field in Wix Corvid

I have event table in Corvid Database, it has Event_Id column for every new event which is not asked from the user in the form.
I used the following code to get the number of rows and generate id from that which works good now:
let count = 0;
$w("#collection").onReady( () => {
count = $w("#collection").getTotalCount(); // 23
count++;
} );
$w('#btnSub').onClick( ()=>{
const newRequest = {
eventid:('event_'+count),
title: $w('#title').value
}
wixData.insert('event_instance', newRequest);
but this can lead to duplication of event id as I delete one of the row from collection
Can you please find a solution for this?
Thanks
You need to use dropdowns in #myElementID
This similar to this in SQL.
if not exists (select * from Delegates d where d.FromYr = #FromYr and d.MemNo = #MemNo)
INSERT INTO Delegates ([MemNo],[FromYr],[ToYr]) values(#MemNo, #FromYr,#ToYr)
Else refer this
Make sense get count before each insert
$w('#collection').onReady( () => {
$w('#btnSub').onClick( () => {
const count = $w('#collection').getTotalCount() + 1; // here
wixData.insert('event_instance', {
eventid: ('event_' + count),
title: $w('#title').value
});
});
});

rxjs join and filter an observable based on values from a different observable

How do I filter an observable using values from another observable, like an inner join in SQL?
class Item {
constructor(public name: string public category: string) {
}
}
class NavItem {
constructor(public key: string public isSelected: boolean = false) {
}
}
// Build a list of items
let items = of(new Item('Test', 'Cat1'), new Item('Test2', 'Cat2'))
.pipe(toArray());
// Determine the unique categories present in all the items
let navItems = from(items)
.pipe(mergeAll(),
distinct((i:item) => i.category),
map(i=>new NavItem(i.category)),
toArray());
I'm building a faceted search so let's say that in the UI, the "Cat1" NavItem is selected, so I want to produce an observable of all the items that have that category. After filtering down to the selected NavItem, I'm not sure how to bring in the Items, filter them down and spit out only those Items that mach a selected category. Here's what I have:
let filteredItems = navItems.pipe(
mergeAll(),
filter(n => n.isSelected))
// join to items?
// emit only items that match a selected category?
Expected result would be
[{name: 'Test', category: 'Cat1'}]
If I understand correctly, you want to select a certain navItem representing a certain category and then select all the items which have such category.
If this is true, than you can consider to create a function or method such as this
selectedItems(categoryId) {
return items.pipe(filter(item => item.category === categoryId));
}
Once you click the navItem then you raise an event which references the navItem and therefore the category id you are interested. You have then to call selectedItems function and pass the category id you selected. This will return an Observable which emits all the items of the category you have selected.
I finally got back around to looking at this and I figured out how to solve this. I needed to use switchMap to join the observables together in the same context. Then I can use map to emit all relevant items:
let filteredItems = from(items)
.pipe(mergeAll(),
switchMap((i) => navItems
// Get only navItems that are selected
.pipe(filter(ni => ni.isSelected),
// Convert back to array so I can if there are any selected items
// if zero, then show all items
toArray(),
map((nav) => {
if(nav.lengh > 0) {
// If the item's category matches, return it
return nav.some(x => x.key == i.category) ? i : null;
}
// If no categories were selected, then show all
return i;
})
}),
// Filter out the irrelevant items
filter(x => x !== null),
toArray()
);

Parse Server relation.add() not working

Issue Description
If I create a relation and use the relation.add() method on it nothing happens.
Steps to reproduce
let Booking = Parse.Object.extend("Booking")
let bookingQuery = new Parse.Query(Booking)
bookingQuery.get(newBookingObject.id, {
success: booking => {
console.log("invites", invites)
// prints array of existing ParseObjects from another class
let relation = booking.relation("invites")
console.log(relation)
// prints new relation with key "invites" and parent "Booking"
relation.add(invites)
console.log(relation)
// prints exactly the same relation object as before - nothing changed
booking.save().then(res => console.log(res))
// an empty relation is added
},
error: error => console.log("error", error)
// no errors
})
Expected Results
relation.add(arrayOfParseObjects) should add objects to relation
Actual Outcome
Nothing happens
insted of
relation.add(invites)
please try the following
for (var i =0; i<invites.length;i++){
relation.add(invites[i])
}
Regards

LINQ EF C# Select

I am new to Linq and EF; my project is in MVC3. I am tyring to do a Select, and would like to add (Where or if) to exclude a record when specific item value is less than 1.
Here is my script
.Select(item => new AreaModel
{
ID = item.ID,
Name = item.Name,
PersonID = item.PersonID,
}) ;
In this case if the PersonID is less than 1 exclude this record.
Thanks in advance
you should basically end up with something like:
EntityObject.Where(x => x.PersonID >= 1)
.Select(item => new AreaModel
{
ID = item.ID,
Name = item.Name,
PersonID = item.PersonID,
});
A good starting point for LINQ are the 101 LINQ samples http://msdn.microsoft.com/en-us/vcsharp/aa336746
Happy LINQ'ing
insert .Where(item => item.PersonID > 0) before .Select.

Resources