Invalid KeyConditionExpression: An expression attribute value used in expression is not defined - database

aws dynamodb query --table-name shoutout-testing --key-condition-expression "Model = :a"
I tried this query but it's saying that :a is not defined

You need to also pass the --expression-attribute-values parameter to define this ":a". For example, --expression-attribute-values '{ ":a": {"S": "hello"} }'. Please check the CLI "query" documentation here.

Related

In MongoDB Projection Operator, what is the meaning of the parameter "1" in "<array>.$" : 1

I'm starting to learn MongoDB, currently, I'm on the Projection Operator lesson. I want to ask about $ (projection). According to MongoDB document, the syntax is like
db.collection.find( { <array>: <condition> ... },
{ "<array>.$": 1 } )
I want to ask about the parameter "1" in { "<array>.$": 1 }. What is the meaning of that? At first, I think it means "first element" but when I change it to "2" it doesn't show the second element, it was still the same. I can't find any information about this parameter on the internet
If you pass 1 as a value of some field in the projection, you are specifying that you want that field to be included in the result.
That is the optimization, since not all the fields will be sent back (default), but only the fields that you specified.

typescript problem in implementing rtl support for material-ui with emotion

I am trying to implement rtl support in a project using material-ui, as described here. my problem is in stage 4.1. I am trying to create a new cache instance that uses the stylis-plugin-rtl. the example povided in the documentation is in javascript & I'm trying to port that into typescript. I have two problems. first, I am trying to pass stylis plugins to the createCache function but I get this error:
Type '(element: Element, index: number, children: Element[], callback: Middleware) => string | void' is not assignable to type 'Plugin'.
Types of parameters 'element' and 'context' are incompatible.
Type 'import("/home/ehsun/Desktop/volkswagen/packages/swiss-army-knife/node_modules/#emotion/stylis/types/index").Context' is not assignable to type 'Element'.ts(2322)
which I bypassed like this:
const cacheRtl = createCache({
key: 'muirtl',
stylisPlugins: [
(prefixer as unknown) as StylisPlugin,
(rtlPlugin as unknown) as StylisPlugin,
],
});
the second problem is that the CacheProvider component has a problem with the type of the created cache & gives this warning:
Property 'insert' is missing in type 'import("/node_modules/#emotion/utils/types/index").EmotionCache' but required in type 'import("/node_modules/#emotion/react/node_modules/#emotion/utils/types/index").EmotionCache'.ts(2741)
index.d.ts(26, 3): 'insert' is declared here.
index.d.ts(338, 9): The expected type comes from property 'value' which is declared here on type 'IntrinsicAttributes & ProviderProps<EmotionCache>'
which I bypassed by casting the cache as any
<CacheProvider value={cacheRtl as any}>{children}</CacheProvider>
I feel like both solutions are wrong/incompelete, and a result of me being a bit inexperienced with typescript, so I would love to know if you people had a better idea. thanks in advance.

Change type of state depending on props - React Typescript

I have a form component "AddBooking" that takes the following prop:
type AddBookingProps = { edit?: Booking };
If this "edit" prop is passed in, I want to render the form with the values set. If it isn't passed in, it becomes a "create" blank form. This is how I'm trying to use the state.
const [currentBooking, setBooking] = useState<NewBooking | Booking>(
edit ? edit : emptyBooking
);
emptyBooking is just a load of empty strings in a NewBooking type to initialize the state.
The difference between the types "Booking" and "NewBooking" is that "Booking" has a required "_id" type whereas "NewBooking" doesn't.
The methods I have for editBooking and addBooking required types "Booking" and "NewBooking" respectively. This is where I get type errors:
if (edit) {
bookingContext.editBooking(currentBooking);
handleClose();
} else {
bookingContext.addBooking({
...currentBooking,
bookedBy: uContext.user.username
});
handleClose();
}
I get a type error when calling editBooking:
Argument of type 'NewBooking | Booking' is not assignable to parameter of type 'Booking'.
Property '_id' is missing in type 'NewBooking' but required in type 'Booking'.
Any ideas how I can get around this without the "any" type?
Thanks so much
This maybe a use case for a type guard https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types
A function you define to check that _id is actually on the type. This is probably good practice as you don't want the user to edit a booking that doesn't yet exist

SharePoint React pnpjs

I am working on a react project for SharePoint framework.
My question is a more or less general question.
I came across a certain problem which I don't understand:
I tried to use sp.search with an object matching the SearchQuery interface, but did this in a class extending react.component
Code:
public search(query: string, properties: Array<string>, rowLimit: number): Promise<SearchResults> {
return new Promise<SearchResults>(async (resolve) => {
let result = await sp.search(<SearchQuery>{
Querytext: query,
SelectProperties: properties,
RowLimit: rowLimit
});
resolve(result);
});
}
As you can see, this is just a basic search function. If I use sp.search in a class that does not extend react.component or if I don't use the searchquery instance, but a plain querystring everything works fine.
I seem to be a type error, but honestly, I don't get what's happening.
Error:
[ts]Argument of type 'Element' is not assignable to parameter of type 'SearchQueryInit'. Type 'Element' is not assignable to type 'ISearchQueryBuilder'.
Property 'query' is missing in type 'Element'. [2345]
[ts] JSX element 'SearchQuery' has no corresponding closing tag. [17008]
[ts] 'SearchQuery' only refers to a type, but is being used as a value here. [2693]
So I decided to just write a service that's using pnpjs and that's totally fine, especially since I didn't plan to use pnpjs in a component, that was just to be a bit faster and have something to test and to work with. but nevertheless, I really would like to understand what is going on. Btw I'm using TypeScript, if that's of interest.
Apparently those errors occur due to a limitation cased by the use of <T> for generic type parameter declarations combined with JSX grammar, refer this issue for a more details (which is marked as a Design Limitation)
To circumvent this error, create the instance of SearchQuery:
const searchQuery: SearchQuery = {
Querytext: query,
SelectProperties: properties,
RowLimit: rowLimit
};
and then pass it into sp.search method:
let result = await sp.search(searchQuery);

local variable 'results' referenced before assignment

I want to retrieve all indexes under elasticsearch index folder. I got this error.
UnboundLocalError at /tjobfucksearch/
local variable 'results' referenced before assignment
my views.py
from haystack.query import SearchQuerySet
def fucksearch(request):
query = request.GET.get('q', '')
if query:
results = SearchQuerySet().all()
return render_to_response("tjob/fucksearch.html", {
"results": results,
"query": query
})
my urls.py
url(r'^tjobfucksearch/$', 'tjob.views.fucksearch'),
Plus: haystack 2.0.0, django 1.4
Any advice would be appreciated. Plz help me.
Consider the case where no q parameter is provided. Then query is set to '', the if query condition fails, so results is not set (not even set to None; Python doesn't know about the name results at this point). So it fails when you try to get the value from results to pass it into the context dict for render_to_response. Perhaps add:
results = None
before:
if query:
....
This way, results will always be defined by the time you need to pass it to render. (You still have to handle the none-results case in your template!)

Resources