miércoles, 26 de julio de 2023

SQL: Sql Server Profiler (what is getting executed in the db?


Remove everything but 'Stored Procedures', check 'Show All Columns' and then click on 'Column Filters' and search for 'DatabaseName' add in 'Like' (or 'Not Like', depends) 'CaseManagementWrite' then 'Application Name' click 'Not Like', 'Microsoft JDBC Driver for SQL Server'.



 

jueves, 22 de abril de 2021

MySql: Execute SQL with command line

1) Single sql file

Using MySQL Command Line Client

if you need to execute it on a particular db, first:

use <db_name>

then:

source <full_path_of_file>

in windows you need to use '/' instead of '\'

2) Multiple sql files (in Windows)

open bash terminal navigate to the folder where the sql files are and then execute:

cat *.sql | mysql -u <user> -p <db_name>

viernes, 22 de enero de 2021

MySQL: Dump command

mysqldump --databases --user=user_name --password --host > path_to_dump_file // Dumps entire db mysqldump --user=user_name --password --host hostvalue which_db table_1 table_2 ... table_n > path_to_dump_file

lunes, 2 de octubre de 2017

Mongoose: Schema

var mongoose = require('mongoose');
mongoose.Promise = global.Promise;

mongoose.connect('mongodb://localhost:27017/TodoApp');

var TodoSchema = mongoose.model('Todo', {
text: {
type: String,
required: true,
minlength: 1,
trim: true
},
completed: {
type: Boolean,
default: false
},
completedAt: {
type: Number,
default: null
}
});

var newTodo = new TodoSchema({
text: 'Cook dinner',
});
newTodo.save().then((doc) => {
console.log(JSON.stringify(doc, undefined, 2));
}, (error) => {
console.log('Unable to save: ', error);
});

Moongose: Start

var mongoose = require('mongoose');
mongoose.Promise = global.Promise;

mongoose.connect('mongodb://localhost:27017/<your_app>');

viernes, 29 de septiembre de 2017

Mongodb: Update

Documentation:
https://docs.mongodb.com/manual/reference/operator/update/

Definition

db.collection('db_name').findOneAndUpdate({
      // Query
    }, {
      // Update
    }, {
      // Options
    }).then((result) => {
  });

Example:

db.collection('Todos').findOneAndUpdate({
      _id: new ObjectID("59ce69b18bec45c336c4ef4a")
    }, {
      $set: {
        completed: true
      }
    }, {
      returnOriginal: false
    }).then((result) => {
  });

Mongodb: Delete

Setup code

// const MongoClient = require('mongodb').MongoClient;
const {MongoClient, ObjectID} = require('mongodb');

MongoClient.connect('mongodb://localhost:27017/your_app', (err, db) => {
  if (err) {
    return console.log('Unable to connect to MongoDB server');
  }
  console.log('Connected to MongoDB server');

  // Execute code here
});

Delete many

Deletes all documents that match the criteria, DOESN'T return any documents.

  db.collection('your_db').deleteMany({query_object}).then((result) => {
    console.log(result);
  });

Delete one

Deletes the first document that matches the criteria, DOESN'T return that document.

  db.collection('your_db').deleteOne({query_object}).then((result) => {
    console.log(result);
  });

Find one and delete

Deletes the first document that matches the criteria, returns that document.

  db.collection('your_db').findOneAndDelete({query_object}).then((result) => {
    console.log(result);
  });