I woul like to generate random Swiss National Identification Number (AHV/AVS). I found a website that can do that and if I look at the source code of the same page I can alos see the JavaScript code that can generate it. The numbers are generated following this pattern: 756: is the prefix number, it never changes 1234: is a
Tag: javascript
Error with passing in the same variable into multiple parts of SQL statement
So I have a Node.js query that should pass in these three values and update a specific column by a specific amount for a user with a specific id: The ‘sqlStatement’ looks like: As you can see, it should pass in the values such that the SQL statement looks like: I’ve also tried to write sqlStatement as the below (and
Select and join with sequelize
How to make this code with the sequelize? I used include, but it brings all the user data but I only need the name my code: Answer If you just want to reduce User model attributes then just indicate needed attributes in the attributes option: If you want to add a user’s name as a string prop at the same
How to look for a specific thing within a table with postgres/nodejs
I’m currently using postgres, accessing it through a node server. I’m feeling stuck on how I would search for a specific term within a table in order to make a change. I know I can SELECT certain items, but I don’t know how to search within the items. say my table is: animal cuddly scary Medium Dog yes no Small
Cannot connect to database stored on aws from Heroku or Replit websites. (mysql2, node.js)
Problem: My discord.js bot isn’t connecting to the mysql database on aws. The bot is being hosted on replit and also on heroku but for some reason I can’t connect to both. I have tried connecting to the database from my laptop and it worked fine, I even hosted the bot on my laptop to see if there was a
What do I do to user data that is currently not verified?
Good day, I’m new to backend coding. What do I do to user data that did not confirm verification code from email during registration? Should I save it to database forever or do I have to delete it after a set of limited time when verified boolean is not met? I’m sorry if this is so beginner question. Answer It’s
how to sanitize sql.js inputs?
I am using sql.js to manage the SQLite file I created for an electron app. My issue is that I want to make sure all the inputs are sanitized. As of now, I am using statements like so: I’m pretty sure that this way is unsafe and can cause SQL injections. What can I do to prevent such a problem?
Postgresql: How do I use dynamic values when searching jsonb array of objects?
I am currently trying to build a query for finding specfic object within a jsonb array. I have the following query which works fine if I used a hard coded string for the “game” value e.g. However, if I use a dynamic value like I currently do for username, I get invalid json syntax error. e.g. How do I search
Convert Raw SQL to Bookshelf/Knex
I’m trying to convert a simple raw SQL to use Bookshelf/Knex in JavaScript: Original SQL: select * from o where o.id = 1 or o.id = 2 and (o.is_a = true or o.is_b = true) and o.status = ‘good’; I’ve tried to rewrite it in multiple ways using .orWhere .andWhere but cannot get the same result that I get from
Nested SQL.promise() callback in Javascript
I want to write a nested callback JavaScript in order to use the subsequent ID’s of the INSERT statements in the different SQL tables. My code looks as follows: However, when trying to run this with Node.js it says Error: Callback function is not available with promise clients. Do you have a solution to retrieve the insert IDs for the