What is the efficient way of getting all items for a given set of hashkeys from a single table? Table has both hashkey and rangekey.
To retrieve a single item I am using
items = tbl.items.query(
:hash_value => "HashKey1",
:select => :all).select.map {|i| i.attributes}
One way to retrieve all item is to loop through keys which is a terrible solution
hashkeys = %w(abcd efgh xyz)
hashkeys.each do |key|
items[dn] = tbl.items.query(
:hash_value => key,
:select => :all).select.map {|i| i.attributes}
end
I am using ruby client for Amazon DynamoDB.
I did not use ruby client but in comparison with php client you could use an array as hashkey value like:
hashkeys = %w(abcd efgh xyz)
items = tbl.items.query(
:hash_value => hashkeys,
:select => :all).select.map {|i| i.attributes}
Related
I've created a select list item and need to reference this list on another page. how do i get the user input, place it in a variable that can be used to calculate the total value of the selected item on another page?
code for the select list which is displayed on a report to allow for amount to be stated:
select item_id,
itemname,
item_price,
apex_item.hidden(1, item_id) ||
apex_item.hidden(2, item_price) ||
apex_item.select_list(
p_idx => 3,
p_value => nvl(null,'item'),
p_list_values => '1,2,3,4,5,6,7,8,9,10',
p_show_null => 'YES',
p_null_value => 0,
p_null_text => '0',
p_item_id => 'f03_#ROWNUM#',
p_item_label => 'f03_#ROWNUM#',
p_show_extra => 'NO') "item"
from item
the select to display the sum will look something like this:
select itemname,
item_price,
'select list value',
('select list value'* item_price) as sum
from item
how do i get the chosen amount from the select list?
Thanks
Oracle APEX has package APEX_APPLICATION which contains collections with names from G_F01 to G_F50. When you use any function from apex_item to create an item inside a report, you pass a number into p_idx parameter. In your example it is 3 for the select list. This value corresponds to one of collections mentioned above - G_F03 in this case.
All values from user's input are passed to these collections after the submit. So you can to write in the after submit process following code:
for i in apex_application.g_f01.first .. apex_application.g_f01.last loop
insert into my_table (id, new_value)
values (apex_application.g_f01(i), apex_application.g_f03(i));
end loop;
This code shows how to insert values from user's input into my_table. Note, that these collections contain only rows changed by user. If a user gets a report with 10 rows and changes 3 of them, each collection will have 3 elements.
Also, APEX has APEX_COLLECTION API to store temporary data.
For more information, see in the documentation: APEX_APPLICATION, APEX_COLLECTION.
UPD.
There are two ways to work with the data further - using a table or APEX_COLLECTION. I have never worked with APEX_COLLECTION, so here is an example with a table.
If you use a table to store temporary data, you need columns for ID, user's name and data (data from the Select List in your example). On the page with the report you need to do this after the submit:
delete from my_table where user_name = :APP_USER;
for i in apex_application.g_f01.first .. apex_application.g_f01.last loop
insert into my_table (id, new_value, user_name)
values (apex_application.g_f01(i), apex_application.g_f03(i), :APP_USER);
end loop;
On the next page, where you need to use this data, you create the following report:
select t.new_value, ...
from my_table t, ... <other tables>
where t.user_name = :APP_USER
and t.id = ...
and <other conditions>
I have this below statement in my controller and I want to know how to rewrite it in Rails 4
Entry.find(:all, :conditions => [#conditions.keys.join(" AND "), *#conditions.values],:group => "user_id", :select => "SUM(time_spent) AS total_spent")
The condition has the user_id information in it like "user_id=?".
The statement is trying to find the entry for a particular user id and sum the time spent for the user id and group by user id.
For example you can use it
realations = Entry.where(user_id: [1, 2, 3]).select("SUM(time_spent) as total_spent").group(:user_id)
After that you have relation with which you can work
realations.each do |i|
puts i.total_spent
end
I have a DynamoDB table with feed_guid as the global secondary index. I want to query with a set of feed_guid in that table. Since feed_guid is not my primary keys, I can't use getBatchItem. When I tried the following method, I got this error:
Invalid operator used in KeyConditionExpression: OR
$options = array(
'TableName' => 'feed',
'IndexName' => 'GuidIndex',
'KeyConditionExpression' => 'feed_guid = :v_guid1 or feed_guid = :v_guid2',
'ExpressionAttributeValues' => array (
':v_guid1' => array('S' => '8a8106e48bdbe81bf88d611f4b2104b5'),
':v_guid2' => array('S' => '19cab76242a6d85717de64fe4f8acbd4')
),
'Select' => 'ALL_ATTRIBUTES',
);
$response = $dynamodbClient->query($options);
You can't use OR condition. You should use
rangeAttributeName BETWEEN :rangeval1 AND :rangeval2
if possible or
feed_guid IN (:v_guid1, :v_guid2)
See ExpressionAttributeValues and KeyConditionExpression
In order to achieve what you want here, you'll need to take the union of two separate queries.
Currently, DynamoDB's Query API only supports having one condition on Hash AND Range Keys in only the KeyConditionExpression because this limits the items you search and ultimately reduces cost of say a more complex query like what you've described here.
i have tried select fields with doctrine query buidler.
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select('au.id, au.firstName')
->from('Api\V1\Entity\AgencyUser', 'au')
->orderBy('au.firstName', 'asc');
$queryBuilder->andWhere('au.agency = :agencyId')
->setParameter('agencyId', $agency->getId());
print_r($queryBuilder->getQuery()->getResult(Query::HYDRATE_OBJECT));exit;
result :
Array
(
[0] => Array
(
[id] => 1
[firstName] => agency
)
)
why this is an array ? i want to hydrated result. any idea ?
You want to use Doctrine's Partial Object Syntax
$queryBuilder->select('partial au.{id, firstName}')
As to why it's not returning an object, this is from the same documentation linked above:
By default when you run a DQL query in Doctrine and select only a subset of the fields for a given entity, you do not receive objects back. Instead, you receive only arrays as a flat rectangular result set, similar to how you would if you were just using SQL directly and joining some data.
Is there any way to fetch objets from the DB and list them by Category? I have a table Artist which have a Genre and each Genre have a Category, so when I'm choosing Genre at new Artist creation I would like to see them separately by each one Category. I recall that in previous versions you could do something like:
$this->widgetSchema['genre_id'] = new sfWidgetFormChoice(array(
'choices' => array('-- Select --',
'-- Category1 --'=>Doctrine_Core::getTable('Genre')->getGenres('Category1')),
'-- Category2 --'=>Doctrine_Core::getTable('Genre')->getGenres('Category2')),
'multiple' => false, 'expanded' => false
));
And the result was a drop down with 'CategoryX' in bold, followed by respectively genres.
After a deep search all I've found is:
->add('group', 'entity', array(
'class' => 'Vendor\MyBundle\Entity\Group',
'label'=>'Group:',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('g')
->... // whatever you want to do
}
))
I think that is what I need, but have no idea on how to adapt it to what I'm looking for.
Many thanks.