Skip to content

Instantly share code, notes, and snippets.

@marcelino-m
Created August 31, 2016 18:07
Show Gist options
  • Save marcelino-m/690d6963a234e11c1bb1360804b94e9e to your computer and use it in GitHub Desktop.
Save marcelino-m/690d6963a234e11c1bb1360804b94e9e to your computer and use it in GitHub Desktop.
Script para borrar las mensuras sobre el grafo
"use strict";
/**
* Borra todas las mensuras sobre un eje de grafo
*/
var _ = require("lodash");
var Sequelize = require("sequelize");
var conf = require("config");
var dbs = conf.get("db.gpsmina");
var gpscon = new Sequelize(dbs.database, dbs.username, dbs.password, {
host: dbs.host,
port: dbs.port,
dialect: dbs.dialect,
logging: false,
pool: {
max: 5,
min: 0,
idle: 10000
}
});
function sel(uidedge, lev){
let select = `
SELECT
aga.grafo_arista_id, aga.id AS aga_id, aga.desde, aga.hasta
FROM
p AS dp, p AS hp, aristas AS a, grafos AS g, grafo_aristas AS ga, aga
WHERE
dp.id = a.dp_id AND
hp.id = a.hp_id AND
g.id = ga.grafo_id AND
aga.grafo_arista_id = ga.id AND
aga.arista_id = a.id AND
aga.arista_id = '${uidedge}'
AND
g.id IN
(
WITH sec AS (
SELECT
*
FROM
grafos AS g, grafo_tipo_grafos AS gtg WHERE
g.id = gtg.grafo_id AND
gtg.tipo_grafo_opt_id = '7a088137-2c4f-4df5-bac5-a987ee52bccc'
), lev AS (
SELECT
*
FROM
grafos AS g, grafo_tipo_grafos AS gtg WHERE
g.id = gtg.grafo_id AND
gtg.tipo_grafo_opt_id = '${lev}'
)
SELECT sec.grafo_id as id from sec, lev
WHERE
sec.grafo_id = lev.grafo_id AND
sec.padre_id = '80b0398f-a9dd-40fc-8972-a26fbda0ab4c'
)
`;
return new Promise((res, rej) => {
gpscon.query(select, {type: gpscon.QueryTypes.SELECT})
.then(r => {
let agaids = [];
let gaids = [];
_.each(r, item => {
agaids.push(`'${item.aga_id}'` );
gaids.push(`'${item.grafo_arista_id}'`);
});
res({agas: agaids, gas: gaids});
})
.catch(e => rej(e));
});
}
function del(edgeids, levid) {
_.each(edgeids, edgeid => {
console.log(edgeid);
sel(edgeid, levid)
.then(r => {
if (r.agas.length == 0){
return;
}
let again = `( ${r.agas.join(",")} )`;
let gain = `( ${r.gas.join(",")} )`;
console.log("AGA");
gpscon.query(`DELETE FROM aga where id in ${again}`).spread((res, met)=> console.log(met));
console.log("GA");
gpscon.query(`DELETE FROM grafo_aristas where id in ${gain}`).spread((res, met)=> console.log(met));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment