How to use the mysql.insertData function in mysql

To help you get started, we’ve selected a few mysql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taskrabbit / empujar / test / connections / mysql.js View on Github external
it('will create a table with the proper data types', function(done){
        // null, int, float, boolean, small-text, large-text, date, primary key
        var data = [
          {id: 1, counter: 4, happy: true, money: 12.234, when: new Date(1448486552507), small_words: 'a small amount of words', large_words: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque consectetur ullamcorper sapien. Phasellus tincidunt quam eu ligula vestibulum convallis. Nulla facilisi. Nulla aliquam ac elit id venenatis. In hac habitasse platea dictumst. Vestibulum dolor arcu, egestas non lacus ac, cursus semper lacus. Nunc sed commodo quam. Vivamus vitae augue vitae leo vulputate maximus sed sagittis dolor.'}
        ];

        var table = 'monies';

        mysql.insertData(table, data, function(error){
          should.not.exists(error);
          helper.query('describe ' + table, function(error, tableCreate){
          helper.query('select * from ' + table, function(error, rows){
            tableCreate.forEach(function(col){
              if(col.Field === 'id'){          col.Type.should.equal( 'bigint(20)' ); col.Extra.should.equal('auto_increment'); }
              if(col.Field === 'counter'){     col.Type.should.equal( 'bigint(20)' ); }
              if(col.Field === 'money'){       col.Type.should.equal( 'float' ); }
              if(col.Field === 'happy'){       col.Type.should.equal( 'tinyint(1)' ); }
              if(col.Field === 'when'){        col.Type.should.equal( 'datetime' ); }
              if(col.Field === 'small_words'){ col.Type.should.equal( 'varchar(191)' ); }
              if(col.Field === 'large_words'){ col.Type.should.equal( 'text' ); }
            });
            
            rows.length.should.equal(1);
            rows[0].id.should.equal(1);
            rows[0].money.should.equal(12.234);
github taskrabbit / empujar / test / connections / mysql.js View on Github external
it('does a full merge when the primary key is not present', function(done){
        var data2 = [{email: 'brian@taskrabbit.com', first_name: 'brian'}];
        var data3 = [{email: 'evan@taskrabbit.com', first_name: 'evan'}];
        mysql.insertData('users2', data2, function(error){
        mysql.insertData('users3', data3, function(error){

          mysql.mergeTables('users2', 'users3', function(error){
            should.not.exist(error);
            helper.query('select * from users3', function(error, rows){
              rows.length.should.equal(1);
              rows[0].first_name.should.equal('brian');
              done();
            });
          });

        });
        });
      });
github taskrabbit / empujar / test / connections / mysql.js View on Github external
helper.query('describe `users`', function(error, tableCreate){
              tableCreate.forEach(function(col){
                if(col.Field === 'message'){ col.Type.should.equal( 'varchar(0)' ); }
              });

              data = [{message: 'abc123'}];
              mysql.insertData('users', data, function(error){

                helper.query('describe `users`', function(error, tableCreate){
                  tableCreate.forEach(function(col){
                    if(col.Field === 'message'){ col.Type.should.equal( 'varchar(191)' ); }
                  });

                  done();
                });
              });
            });
          });
github taskrabbit / empujar / test / connections / mysql.js View on Github external
mysql.insertData('users2', data2, function(error){
        mysql.insertData('users3', data3, function(error){

          mysql.mergeTables('users2', 'users3', function(error){
            should.not.exist(error);
            helper.query('select * from users3', function(error, rows){
              rows.length.should.equal(1);
              rows[0].first_name.should.equal('brian');
              done();
            });
          });

        });
        });
      });
github taskrabbit / empujar / test / connections / mysql.js View on Github external
buildUserTable(function(){
          var data = [{id: 1, first_name: 'joe'}];
          mysql.insertData('users', data, function(error){
            should.not.exists(error);
            helper.query('select * from `users` where id = 1', function(error, rows){
              rows.length.should.equal(1);
              rows[0].email.should.equal('evan@taskrabbit.com');
              rows[0].first_name.should.equal('joe');

              done();
            });
          });
        });
      });
github taskrabbit / empujar / test / connections / mysql.js View on Github external
mysql.copyTableSchema('users', 'users2', function(error){
            should.not.exist(error);

            var data = [{id: 100, email: 'brian@taskrabbit.com', first_name: 'brian'}];
            mysql.insertData('users2', data, function(error){
              mysql.mergeTables('users', 'users2', function(error){
                helper.query('select * from users2 order by id asc', function(error, rows){
                  rows.length.should.equal(4);
                  rows[0].first_name.should.equal('evan');
                  rows[1].first_name.should.equal('pablo');
                  rows[2].first_name.should.equal('aaron');
                  rows[3].first_name.should.equal('brian');

                  done();
                });
              });
            });
          });
        });
github taskrabbit / empujar / test / connections / mysql.js View on Github external
buildUserTable(function(){
          var data = [{id: 1, first_name: 'evan2'}];
          mysql.insertData('users', data, function(error){
            should.exist(error);
            error.message.should.match(/Duplicate entry/);
            done();
          }, false);
        });
      });