alwint3r / sequelize-datatable-node

MIT License
11 stars 12 forks source link

How to implement raw query ? #4

Closed xeleniumz closed 7 years ago

xeleniumz commented 7 years ago

hi @alwint3r . I have a question how to buid query from raw query sequelize ? assume I have raw query with

var query ="SELECT 
                        radacct.radacctid,
                        radacct.username,
                        radacct.framedipaddress,
                        radacct.acctstarttime,
                        radacct.acctoutputoctets,
                        radacct.nasipaddress,
                        client_detail.browser,
                        radacct.acctstoptime,
                        client_detail.os,
                        client_detail.browser,
                        voucher.groupname,
                        voucher.id
                        FROM
                        radacct
                        LEFT JOIN 
                        client_detail ON client_detail.ip = radacct.framedipaddress
                        INNER JOIN 
                        voucher  ON voucher.username = radacct.username 
                        WHERE
                        radacct.acctstoptime IS NULL";

            var resp = await req.db.sch.query(query, {
                type: req.db.sch.QueryTypes.SELECT,
            });

            var _ = await dataTable(resp, req.query);

Can you explain or give me an exmaple ? because when i 'm testing this code it was response with error UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): TypeError: model.count is not a function

alwint3r commented 7 years ago

I'm afraid the raw query is not supported since the current implementation use model instead of raw query.

xeleniumz commented 7 years ago

Ok. but i think if you can add this feature to node-datatables it will flexible

alwint3r commented 7 years ago

Honestly I need to do a lot of catch up with sequelize because it's been a while since the last time I used sequelize. I am now more focused on IoT projects hence I use C++ more than JS now.

xeleniumz commented 7 years ago

what is your IoT project ? I'm interesting. Do you want to share it ?

alwint3r commented 7 years ago

Well almost all of them were projects of a startup that I work with. But you can find public projects & repositories at github.com/dycodex, also you can check out learn.makestro.com for more public project by our community.

Okay I'm going to close this issue since this discussion goes out of topic, don't hesitate to file new issue if there are bugs or questions.

xeleniumz commented 7 years ago

thank you for your advice