Completado

node.js function to generate sql statement

generate sql statement based on table array

I have a one to many database schema tables

let's say we have the following one to many schema

company has many

departments with many

employees

i need to a node.js function to create multiple sql statements that clear all the orphan records which do not have parent records

so in the example above

company : companyid , companyName

department : departmentid , departmentName, companyid

employees : employeeid , employeename, departmentid

so if i pass the following array to the needed function in the exact order:

arrTables =

[

{

table : 'employee',

id : 'employeeid',

parentfield : 'deparmentid'

}

,

{

table : 'department',

id : 'departmentid',

parentfield : 'companyid'

}

,

{

table : 'company',

id : 'companyid',

}

];

it will generate the necessary sql statments to delete the orphan records from the employee table to the deprtement table and from the department table up to the company table

e.g.

delete from employees left join department on [url removed, login to view] == [url removed, login to view] where employeeid == null;

delete from department left join company on [url removed, login to view] == [url removed, login to view] where companyid == null;

below is the functionformat

function sqlClearOrphansFromTables(arrTables) {

//*********************

YOUR MAGIC HERE

//*********************

return

[

'delete from employees left join department on [url removed, login to view] == [url removed, login to view] where employeeid == null;',

'delete from department left join company on [url removed, login to view] == [url removed, login to view] where companyid == null;'

]

}

arrTables can be an array of infinite number of relational table, e.g. i can pass:

arrTables =

[

{

table : 'currentprojects',

id : 'currentprojectid',

parentfield : 'employeeid'

}

,

{

table : 'employee',

id : 'employeeid',

parentfield : 'deparmentid'

}

,

{

table : 'department',

id : 'departmentid',

parentfield : 'companyid'

}

,

{

table : 'company',

id : 'companyid',

}

];

in which case it will generate 3 delete statements

Thanks in advance

after looking at the pseudocode above, seems it is more as text concatination with javascript, seems node.js is an overkill for the requirements, basic javascript should do the job.

Habilidades: Javascript, node.js, SQL

Ver más: number function, function number, clear array c, c clear array, node, generate 500, generate node, company function, sql relational tables, sql multiple tables, create node, node based, delphi generate sql statement, generate table table schema, magic number, create table schema table, sql create schema, sql statement delete table, create sql database schema, delete sql statement, sql delete, sql create database schema, sql parent, create database schema sql, array sql

Información del empleador:
( 2 comentarios ) Mountain View, United States

Nº del proyecto: #7610680

Adjudicado a:

andriy3s

Hi, I'm high rated coder from Ukraine. I've more than 12 years in the experiences of the database developing. My skills are includes MS SQL, PostgreSQL, SQLite, MySQL, MS Access, Sybase etc. Also I've high skills Más

$45 USD en 0 días
(13 comentarios)
3.3

14 freelancers están ofertando el promedio de $124 para este trabajo

ngscoder

Hi I have read and understood your requirements. I am willing to help you with this project and any future projects. Please get in touch to discuss further. Regards AZ

$263 USD en 3 días
(39 comentarios)
6.1
srinichal

I am an expert in delivering customized solutions and look forward to discuss further about the project.

$147 USD en 3 días
(24 comentarios)
5.3
techwelfare

Hello Let's explore the requirement and kindly let us know if you would like us to share our skills & experiences with previous development. Thanks and Regards Audri

$171 USD en 4 días
(17 comentarios)
5.0
martinlynas

Hi - I'd love to work with you on this - it's pretty straightforward - I have plenty of experience of javascript and sql. Hope to hear from you soon. Martin.

$155 USD en 3 días
(8 comentarios)
3.1
imagepresslib6

Hi sir. Thank you for your post. I read your description carefully. As being an expert in javacript and node.js, i am very interesting in your project. I have gained enough experiences in javascript and node.js for Más

$200 USD en 3 días
(3 comentarios)
2.3
Lakret

Hi. Done it already: [url removed, login to view] I will send you the function after you make and release milestone. Thanks.

$50 USD en 0 días
(2 comentarios)
2.4
saidmohamed11

I am a talented Developer with years of experience and educational training. If hired by you I will deliver my best work at a high standard. I look forward to being hired by you for your jobs.

$233 USD en 3 días
(1 comentario)
0.8
jrszapata

This work can be complete today. This function could run faster by passing the related tableName. This should be optional, of course. Choose me and you will have your Function created today.

$150 USD en 1 día
(0 comentarios)
0.0
forward1387

I'm able to organize these script through sworm ORM(Object Relational Mapping). It will be easy maintainable and supporting. Script will be suitable for most SQL(Oracle, MSSQL, Postgresql, MySql).

$100 USD en 1 día
(0 comentarios)
0.0
avicene

I have the experience and have worked on similar tasks for a major bank in the states. I also used node js on a couple of projects for startups in the states.

$155 USD en 3 días
(0 comentarios)
0.0
splittorff

It can be done rather simple - do you want your nodejs run on your desktop on on a server ? - shall it run un der cron to take new orphans ? Yours erik

$155 USD en 3 días
(0 comentarios)
0.0
phthanh85

- After looking at your requirement, I tried writing a JavaScript code and finished it within about 1 hour. - Then I use it to generate the SQL commands. Below is an example delete currentproject from currentproject Más

$45 USD en 0 días
(0 comentarios)
0.0
BloodGood

I have been working on Javascript day in day out for the past 3 years. I am pricing this low since I believe the task is simple.

$35 USD en 1 día
(0 comentarios)
0.0
Moksh11

Hi bro, this is an easy job, I will start doing it immediately after accepting my bid, and I will deliver the code to you within few hours.

$35 USD en 1 día
(0 comentarios)
0.0