Limit volume of database rows
Options
![Rand](https://us.v-cdn.net/6037124/user_avatars/3992907.jpg)
Rand
Member ✭
Hey all, does anyone know if there’s a way to set a rule of maximum number of database rows?
I’m creating a voucher code system and want to stipulate that no more than 50 rows (vouchers) can be redeemed, each with unique identifiers.
Thanks in advance 😊
I’m creating a voucher code system and want to stipulate that no more than 50 rows (vouchers) can be redeemed, each with unique identifiers.
Thanks in advance 😊
Comments
-
You want to limit the number of rows on the whole table? Or, you want to limit the number of records for a particular criteria .. such as "Only allow 50 records for #voucher_company#"
I'm guessing it's the later option ... you can do this with logic inside of your endpoint or function.
When the request to add a new comes in, use a Query All function, with a where clause. Only select the vouchers with the same identifier. On the output, use Count.
Now, your function will return the number of vouchers that currently exist.
Then, use a Precondition (under utility functions).Set the expression to the number of vouchers being less than or equal to 50.
If there are 50 or more vouchers, the function will end. IF not, it will allow the function to continue. Then, place your put code below the pre condition.
[Screen Shot 2022-04-20 at 2.22.14 PM.png][Screen Shot 2022-04-20 at 2.20.28 PM.png][Screen Shot 2022-04-20 at 2.19.59 PM.png] -
Hey Rand - a quick solution could be to:
1. Query All Records, change return type to count
2. Precondition, set so the count less than or equal to 50
3. The rest of your function stack logic.
This way you can stop execution if the count reaches 50 -
Awesome, thank you both!
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback