Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3812

Knex and MSSQL Stored Procedures

$
0
0

I've successfully installed, and I'm running, the DT Editor/Node libraries with our own production SQL server, using the demo files you've provided, and it's working :smile:

A lot of my work revolves around Stored Procedures.

Would there be a way to expand the example below so that the Fields being established are "bound" to the results of the Stored Procedure? How do I get the "Datatables Node Library" and KNEX to work with the results of the stored procedure?

In my journeys, I have established a "data model" using Express and Sequelize. My Express route uses Sequelize to run a specific Stored Procedure, and the results are returned as JSON.

So, I can create a result set in my Stored Procedure to match the Fields in the example below... but I don't know how to "instantiate" "Editor-Server" instances of those Fields.

KNEX appears to have a "raw" option, so theoretically, I could use it to run a SP: knexjs.org/#Raw

Thank you for any advice you may have.

router.all('/api/staff', async function(req, res) {
    let editor = new Editor(db, 'datatables_demo').fields(
        new Field('first_name').validator(Validate.notEmpty()),
        new Field('last_name').validator(Validate.notEmpty()),
        new Field('position'),
        new Field('office'),
        new Field('extn'),
        new Field('age')
            .validator(Validate.numeric())
            .setFormatter(Format.ifEmpty(null)),
        new Field('salary')
            .validator(Validate.numeric())
            .setFormatter(Format.ifEmpty(null)),
        new Field('start_date')
            .validator(
                Validate.dateFormat(
                    'YYYY-MM-DD',
                    null,
                    new Validate.Options({
                        message: 'Please enter a date in the format yyyy-mm-dd'
                    })
                )
            )
            .getFormatter(Format.sqlDateToFormat('YYYY-MM-DD'))
            .setFormatter(Format.formatToSqlDate('YYYY-MM-DD'))
    );

    await editor.process(req.body);
    res.json(editor.data());
});

Viewing all articles
Browse latest Browse all 3812

Trending Articles