I want to add items individually with datastore component, however. The datastore compares it as “OR” when it is done upert and adds or updates accordingly.
This is exactly what I want to do;
Country
State
Germany
Hamburg
Turkey
Istanbul
Turkey
Adana
I want to add 2 different countries and 3 different states as above. However, it is not possible to reach the above result with the existing datastore component.
(not sure) , because when the datastore component is updated, it searches for “Country or State” with the OR statement. How can I do this using the “AND” statement. In short, I want every new line added to be unique
It’s a bit involved, but you can do this with a flow that checks the data store before adding an item.
Try out this page. Just pass the country and state to the flow, instead of directly upserting to the data store.
<!doctype html>
<html>
<head>
<base href="/">
<script src="dmxAppConnect/dmxAppConnect.js"></script>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="bootstrap/4/css/bootstrap.min.css" />
<script src="dmxAppConnect/dmxFormatter/dmxFormatter.js" defer=""></script>
<script src="dmxAppConnect/dmxDatastore/dmxDatastore.js" defer=""></script>
</head>
<body is="dmx-app" id="valid">
<script is="dmx-flow" id="flow_add_data_store" type="text/dmx-flow">{
meta: {
$param: [
{type: "text", name: "country"},
{type: "text", name: "state"}
]
},
exec: {
steps: {
condition: {
if: "{{! (datastore1.data.where(`country`, $param.country, '==').hasItems() && datastore1.data.where(`state`, $param.state, '==').hasItems())}}",
then: {
steps: {
run: {
action: "{{datastore1.insert({country: $param.country, state: $param.state})}}"
}
}
}
}
}
}
}</script>
<dmx-datastore id="datastore1"></dmx-datastore>
<button id="btn_germany_hamburg" class="btn btn-primary" dmx-on:click="flow_add_data_store.run({country: 'Germany', state: 'Hamburg'})">btn_germany_hamburg</button>
<button id="btn_turkey_istanbul" class="btn btn-success" dmx-on:click="flow_add_data_store.run({country: 'Turkey', state: 'Istanbul'})">btn_turkey_istanbul</button>
<button id="btn_turkey_adana" class="btn btn-info" dmx-on:click="flow_add_data_store.run({country: 'Turkey', state: 'Adana'})">btn_turkey_adana</button>
<div dmx-repeat:repeat1="datastore1.data">
<p dmx-text="country+' -- '+state"></p>
</div>
<script src="bootstrap/4/js/popper.min.js"></script>
<script src="bootstrap/4/js/bootstrap.min.js"></script>
</body>
</html>
1 Like
Thanks @mebeingken I followed the same way and solved the problem. It would be much easier if this were to be used natively in wappler.
Antony
January 2, 2021, 10:06pm
4
I do this by adding a field to the data store called country_state which would have values such as Germany_Hamburg.
Then you just upsert where country_state = country+’_’+state
2 Likes
@Antony thanks … I solved it with flow component, but that might be an interesting solution.
I hope @patrick also suggests a way. (when he’s back from vacation).