Tuesday 28 March 2017

What convenience functions you'd like for a MySQL interface and how'd you name them?

In Node.js, there are two drivers to use MySQL:http://ift.tt/2o1HZp2 drivers are low level interfaces to MySQL that share an identical API. I see a lot of projects directly depending to these modules. The problem is that these projects lack at least one level of abstraction.I have set out to improve this. My main beef with the existing projects is:lack of strict typeslack of convenience methods for common operationshard to debug/ logerror handling requires tapping into the error codesI have started to write http://ift.tt/2ouixFj to address all of these issues. It is not a complete project – I develop it as new requirements crystallise. (Note, it is a thin layer on top of mysql2, no one wants to reinvent the wheel here.)At the moment, mightyql allows to:log queries using DEBUG=mightyql*. The log includes the original query, execution time and the count of the rows.includes convenience methods: one, many, any, insertone returns one row. Throws error if no rows found. Throws error if more than one row is found. (Query should be constructed with LIMIT 2)any returns rows array (unlike query, it does not return fields)many returns one or more rows. Throws error if no rows found.insert returns {insertId} object.I'd like to add methods that return the first column value. I was thinking oneColumn, anyColumn, manyColumn. Though, this naming is slightly confusing (any column especially). What you'd suggest for alternative names?Note: The reason for using a different method for each result type is to enable simple use of strict types (Flow type in this case).Regarding the error handling, I've madeWhat operations with MySQL you often perform in your code base and have you thought of higher-level abstractions?

Submitted March 28, 2017 at 01:48PM by gajus0

No comments:

Post a Comment