Simple.Data casting to ToList<string>() - simple.data

I am using Simple.Data and want to know if I can Select a single column and then cast it to a list of string values. For example using the query below I get the error:
Cannot implicitly convert type 'Simple.Data.SimpleRecord' to 'string'
var result = _database.ParentRegionList.All()
.Select(_database.ParentRegionList.RegionName)
.Where(_database.ParentRegionList.RegionName.Like(startsWith + "%"))
.Distinct()
.ToList<string>();
However if I create a class LocationAutoComplete that has a single public property "RegionName" of type string then the cast works fine.
var result = _database.ParentRegionList.All()
.Select(_database.ParentRegionList.RegionName)
.Where(_database.ParentRegionList.RegionName.Like(startsWith + "%"))
.Distinct()
.ToList<LocationAutoComplete>();

The ToList<T> Simple.Data method expects you to be casting the contents of a SimpleRecord to an object, which is why it works with your LocationAutoComplete class. Full details can be found here.
If you are returning only one field which you wish to return as a scalar value or a list of scalar values, use the ToScalar<T> or ToScalarList<T> method instead. Full details can be found here

If RegionName is a varchar then all you need is
var result = _database.ParentRegionList.All()
.Where(_database.ParentRegionList.RegionName.Like(startsWith + "%"))
.Select(_database.ParentRegionList.RegionName)
.Distinct()
.ToList();
You don't need the <string>

Related

Json Path logical NOT operator with Filter not working

I have JSON data and want to use the logical not operator in JSONPath, however, I want to use it dynamically since my input string consists of many filters which I convert into a JSONPath query.
v1/movie?filter=not metadata.sample eq "NETFLIX" this way I am using my APY. This should be converted to [?(!(#['metadata']['PLM-CODE'] == 'NETFLIX'))] using the Filter object of JSONPath.
Now this below one works perfectly
JsonPath.using(configuration).parse(jsonString).read("$.data[?(!(#['metadata']['PLM-CODE'] == 'NETFLIX'))]",typeRef);
but I can not directly add ! when using the code below:
String stringFilter = rightPred.toString();
String notFilterString = "[?(!" + stringFilter.substring(2,stringFilter.length()-1) + ")]";
return Filter.parse(notFilterString);
but parse is converting it to [?(#['metadata']['PLM-CODE'] == 'NETFLIX' ! null)]

Passing list of search string in contains in FilterExpression

Is there any way to pass a list of search strings in the contains() method of FilterExpression in DynamoDb?
Something like below:
search_str = ['value-1', 'value-2', 'value-3']
result = kb_table.scan(
FilterExpression="contains (title, :titleVal)",
ExpressionAttributeValues={ ":titleVal": search_str }
)
For now I can only think of looping through the list and scanning the table multiple times (as in below code), but I think it will be resource heavy.
for item in search_str:
result += kb_table.scan(
FilterExpression="contains (title, :titleVal)",
ExpressionAttributeValues={ ":titleVal": item }
)
Any suggestions.
For the above scenario, the CONTAINS should be used with OR condition. When you give array as input for CONTAINS, DynamoDB will check for the SET attribute ("SS", "NS", or "BS"). It doesn't looks for the sub-sequence on the string attribute.
If the target attribute of the comparison is of type String, then the
operator checks for a substring match. If the target attribute of the
comparison is of type Binary, then the operator looks for a
subsequence of the target that matches the input. If the target
attribute of the comparison is a set ("SS", "NS", or "BS"), then the
operator evaluates to true if it finds an exact match with any member
of the set.
Example:-
movies1 = "MyMovie"
movies2 = "Big New"
fe1 = Attr('title').contains(movies1)
fe2 = Attr('title').contains(movies2)
response = table.scan(
FilterExpression=fe1 or fe2
)
a little bit late but to allow people to find a solution i give here my method.
lets assume that in your DB you have a props called 'EMAIL you want to filter your scan on this EMAIL with a list of value. you can proceed as following.
list_of_elem=['mail1#mail.com','mail2#mail.com','mail3#mail.com']
#set an empty string to create your query
stringquery=""
# loop each element in your list
for index,value in enumerate(list_of_elem):
# add your query of contains with mail value
stringquery=stringquery+f"Attr('EMAIL').contains('{value }')"
# while your value is not the last element in list add the 'OR' operator
if index < len(list_of_elem)-1:
stringquery=stringquery+ ' | '
dynamodb = boto3.resource('dynamodb')
# Use eval of your query string to parse the string as filter expression
tableUser = dynamodb.Table('mytable')
tableUser.scan(
FilterExpression=eval(stringquery)
)

Invalid UpdateExpression when using parameter from ValueMap as index (REMOVE myArray[:index])

I try to remove an element from an array. This operation
UpdateItemSpec updateItemSpec = new UpdateItemSpec()
.withPrimaryKey("id", id)
.withNameMap(new NameMap().with("#P", "myArray"))
.withValueMap(new ValueMap().withInt(":index", index))
.withUpdateExpression("REMOVE #P[:index]");
table.updateItem(updateItemSpec);
results with com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: Invalid UpdateExpression: Syntax error; token: ":index", near: "[:index]"
If I remove ValueMap and concat string like this "REMOVE #P["+index+"]" it works fine but this solution looks ugly (like old bad SQL injection stuff). Is there a way to provide an index as a parameter?
REMOVE - Removes one or more attributes from an item
REMOVE - The UpdateExpression is expected to have attribute name only for REMOVE. It should not contain attribute value similar to SET.
There is no alternative other than String concatenation by some means.

Error 1123: Filter operator not supported on type object

I have a a structure like this:
e.item.fatturato_ac_s1
e.item.fatturato_ac_s2
e.item.fatturato_ac_s3
e.item.fatturato_ac_s4
[...]
and so on...
in order to compute dinamically the string I wrote:
e.item.(myStr.toString()) where myStr (type string) = "fatturato_ac_s" + Index (so I can have fatturato_ac_s1, fatturato_ac_s2, ...)
I can correctly retrieve the value of e.item.(myStr.toString()) (a numeric value), but if I try to put it in a variable I get the error in the title:
myVariable = e.item.(myStr.toString())
myVariable is a Number.
I also tried:
myVariable = Number(e.item.(myStr.toString()))
but doesn't work... the same if I try String to String....
How can I solve it!?!!?
thank you!
This is correct syntax:
myVariable = Number(e.item[myStr])

How to convert a String into the property name of an object in Flex

I need to get the value of the item clicked and the name of the columns.
for each(item in colunas) {
var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem.itemok); // show value of column
}
But this way it returns 'undefined'.
But if I put the name already in function, I can get the correct data, example:
Alert.show(''+datagridlist.selectedItem.create); // create is a column name in mysql
But this variable must be created dynamically, example:
var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem.itemok); // show value of column
Could someone help me? I'm at it on time and I can not convert the string to column name.
I thank you all now
for each(item in colunas)
{
var itemok:String = item.dataField;
Alert.show(''+datagridlist.selectedItem[itemok]);
}
The dot syntax to access properties/fields works only with property names. When the property name is stored in a string, use square brackets.
var t:String = "value";
//The following three lines are the same and will work
trace(something.value);
trace(something["value"]);
trace(something[t]);
//but this one won't
trace(something.t);

Resources