sequelize: how to find and update mysql rows in node.js

I'm new on node.js and try to rebuild the code from PHP to nodejs with the very interesting tool sequelize.

I read the squelize documentation and searched here and at google, but i cant figure out the way to do that in a correct way and how to build this.

It's important that the code just go on, if the results from the mysql-db are aviable and without errors... hope you can help me out to understand this.

Kind regards

function mysqlQuery(mysql, conf, query, callback) { var client = mysql.createClient({ user: conf.user, password: conf.password }); client.query('USE ' + conf.database, function() { client.query(query, function(err, results) { callback(client, err, results); }); }); } sockets = []; var net = require('net'); var server = net.createServer(function(socket) { var q_balance = "SELECT datum_von, datum_bis, jahr, unique_id, game_status, wert FROM xxxxxx WHERE datum_von <= \"" + game_datum + "\" and datum_bis >= \"" + game_datum + "\" and game_name = \"" + game_name + "\" LIMIT 1;"; mysqlQuery(mysql, conf, q_balance, function selectCb(client, err, results) { if (err) { throw err; } for (var i_db14 in results) { var daten_db14 = results[i_db14]; datum_von_cj = daten_db14.datum_von; datum_bis_cj = daten_db14.datum_bis; jahr_cj = daten_db14.jahr; game_status_cj = daten_db14.game_status; unique_id_cj = daten_db14.unique_id; wert_cj = daten_db14.wert; } if (datum_von_cj === "" || datum_bis_cj === "" || jahr_cj === "" || game_status_cj === "" || unique_id_cj === "" || wert_cj === "") { error_buy = 1; } if (error_buy === 0) { for (i_check1 = 0; i_check1 < unique_id_anzahl_check; i_check1++) { if (game_name === "game1") { preis = preis_game1; } else if (game_name === "game2") { preis = preis_game2; } else if (game_name === "game3") { preis = preis_game3; } else { error_buy = 1; } if (error_buy === 0) { preis_berechnung[i_check0]['preis'] = preis_berechnung[i_check0]['preis'] + preis; sr_tmp = randomString(10); sr = game_name.toUpperCase() + "-" + sr_tmp; sr_tmp = ""; var q_balance6 = "INSERT INTO xxxxxx2 (user_id,game,game_id,...) VALUES (\"" + user_id_db + "\",\"" + game_name + "\",\"" + game_id + "\");"; mysqlQuery(mysql, conf, q_balance6, function selectCb(client, err, results) { if (err) { throw err; } var q_balance7 = "UPDATE " + game_name + " SET tickets = tickets + 1 WHERE unique_id = \"" + game_unique_id + "\" LIMIT 1;"; mysqlQuery(mysql, conf, q_balance7, function selectCb(client, err, results) { if (err) { throw err; } client.end(); }); client.end(); }); } } } client.end(); });

Category:mysql Views:2 Time:2012-03-10

Related post

  • How do I update MySQL row in PHP? 2009-03-22

    I have a MySQL database that I'm working with, but when I try to update a row in it, it doesn't work. Here's the update code I'm working with: mysql_query("UPDATE offtopic SET next = '$insert' WHERE id = '$id'"); --------------Solutions-------------

  • php script not updating mysql row 2012-03-23

    I'm trying to update a row in my database but it's not running. Below is the current script I have that gets values from an ajax call. I've checked the call and it is sending the right information. know that I do have the connection values at the top

  • Best strategy to update mysql rows with PHP? 2012-05-02

    Say I've 5 rows with id, catname and order fields: +----+----------+-----+ | id | catname |order| +----+----------+-----+ | 1 | cat1 | 2 | | 2 | cat2 | 1 | | 3 | cat3 | 3 | | 4 | cat4 | 5 | | 5 | cat5 | 4 | +----+----------+-----+ and I want to updat

  • Hyperlink(href) to update mysql row 2014-03-19

    I have to buttons witch currently looks like this: <a href="?update_link=a">a</a> <a href="?update_link=b">b</a> I also have 2 rows in a table. Both with 2 fields named «name» and «score» The name is static. One row named a an

  • Update MySQL row automatic at change 2010-07-15

    I got a kind of admin-panel where I want to be able to change customers order status live without refreshing or changing page. I have figured out that I need to use Javascript, AJAX or jQuery for this but since I have no experience for that and have

  • Easier way to update MySQL row based on previous data? 2010-11-10

    I was wondering if there was an easier way to go about updating data in my MySQL database. I have a column called "food" which is an integer. Whenever I want to update the amount of food, I have to SELECT the current amount, create a new variable for

  • Updating display order of multiple MySQL rows in one or very few queries 2009-04-14

    I have a table with say 20 rows each with a number for display order (1-20). SELECT * FROM `mytable` ORDER BY `display_order` DESC; From an admin area you can drag the rows around or type a new number manually for each row. Surely it's not good to lo

  • MySQL update one row when another changes 2009-09-04

    I have a table with products. artID artName stock order 1 cables *100 0 2 cables *1 75 What should I do to asociate these 2 rows and get the stock in sync. The provider sells the cables in bulks on 100 units, and the retail store sells then as unit.

  • How to update multiple rows in the same table of MySQL with PHP? 2009-09-14

    If only one row with a distinct field is to be updated,I can use: insert into tab(..) value(..) on duplicate key update ... But now it's not the case,I need to update 4 rows inside the same table,which have its field "accountId" equal to $_SESSION['a

  • Perl: Update Multiple Rows with one MySQL Call 2010-01-03

    Seems that it may not be possible, but hey I might as well ask, I could be wrong. Was wondering if there's anyway for perl to update multiple rows using one MySQL call, I'm using DBI. Any help or feedback would be greatly appreciated, this is possibl

  • Updating multiple rows in MySQL 2010-07-07

    I'm trying to update multiple rows in one table in MySQL database by doing this. And its not working. $query = "UPDATE cart SET cart_qty='300' WHERE cart_id = '21'; UPDATE cart SET cart_qty='200' WHERE cart_id = '23'; UPDATE cart SET cart_qty='100' W

  • How to UPDATE the same mysql row from multiple scripts at the same time? 2010-09-11

    I am forking some php scripts and I need to update a mysql row to track some progress. I read that I should use InnoDB for this but I coulnd't find any complete example I can understand. A friend told me he uses this php code: mysql_query("SET AUTOCO

  • In MySQL, is it faster to delete and then insert or is it faster to update existing rows? 2010-10-26

    First of all, let me just say that I'm using the PHP framework Yii, so I'd like to stay within its defined set of SQL statement if possible. I know I could probably create one huge long SQL statement that would do everything, but I'd rather not go th

  • Mysql query for updating next row 2010-11-15

    I need to display a news-tip daily and my table structure as below. | id | ndate |News Tip | +------+----------------------+ | 1541 | NULL | news1 | | 1545 | 14-10-2010 | news2 | | 1567 | NULL | news3 | | 1568 | NULL | news4 | | 1582 | NULL | news5 |

  • Update MySQL timestamp even if row data is unchanged 2011-03-11

    I have a PHP script that imports sql scripts into a MySQL 5 database. Each script contains nothing but UPDATE statements that each update 1 row in a table (MyISAM). If a row has not been inside one of these scripts for 2 days it must be deleted. The

  • Update multiple rows with different values in a single query - MySQL 2011-10-13

    I'm new to MySQL. I'm using this to update multiple rows with different values, in a single query: UPDATE categories SET order = CASE id WHEN 1 THEN 3 WHEN 2 THEN 4 WHEN 3 THEN 5 END, title = CASE id WHEN 1 THEN 'New Title 1' WHEN 2 THEN 'New Title 2

  • Insert/Update Multiple Rows in MySQL with PHP and Jquery 2011-11-26

    I have a table that is populated by a MS Sql query from one database that gives me values from patient visits and the revenue generated from those visits. I have a checkbox that populates the corresponding text input box showing that visit was paid f

  • Update multiple rows with multiple values and multiple conditions mysql 2011-12-05

    I am facing a complex situation of SQL queries. The task is to update multiple rows, with multiple values and multiple conditions. Following is the data which I want to update; Field to update: 'sales', condition fields: 'campid' and 'date': if campi

  • Update multiple rows in mysql with php 2011-12-17

    Here is my code below. The problem is when I try to update info it instead clears all records and does not update. How can I get this script to update and not clear. Also, I have used this before and it worked fine but all the sudden it doesn't.. I m

Copyright (C), All Rights Reserved.

processed in 0.081 (s). 11 q(s)