kowainik / mysql-not-so-simple Goto Github PK
View Code? Open in Web Editor NEWMySQL not so simple
Home Page: https://kowainik.github.io/projects/mysql-not-so-simple
License: MIT License
MySQL not so simple
Home Page: https://kowainik.github.io/projects/mysql-not-so-simple
License: MIT License
This is useful for further pattern-matching on the value.
The following is quite problematic, especially if we're going to store everything as TEXT
:
It's enough to test only tuples of length 2 and 3. And by induction we get proper behavior for tuple of every size.
Sometimes you call functions with a lot of SQL queries but current error reporting only shows the error without the SQL query itself. Because of that it's not that easy to find which query is not working. It would be better to add Query
as well to relevant error constructors.
OK
data type contains information about this. And MySQL doesn't support RETURNING id
clause. Maybe it makes sense to have something like:
newtype Id32 = Id32 Int32
executeReturningId :: MySQLConn -> Query -> IO Id32
Every error has the following string at the beginning:
"MySql error: "
Probably can refactor it to not repeat this particular part every time.
And don't forget to update property-based tests.
MySQL doesn't support named parameters on the protocol level. So the only possible way to implement named parameters in our library is the following:
data NamedParam = NamedParam Text Param
(where Text
is the name of the parameter).executeNamed
and queryNamed
with types:queryNamed :: FromRow row => MySQLConn -> Query -> [NamedParam] -> IO [row]
These function will parse Query
and replace all occurrences of :nameOfTheParameter
with ?
and rearrange arguments in [NamedParam]
list according to their occurrence in the Query
. And then these functions just delegate their arguments to query
and execute
functions.
Regarding parsing of Query
: I propose that after :
only alphanumeric characters and underscores are allowed. I hope that :
is not used anywhere in MySQL...
Any thoughts on this?
Currently we don't have tests so testing on CI doesn't make much sense and won't be very useful because without tests we can't verify that tests are actually working on the CI. If we do this issue right now, we probably will need to do it again after we have MySQL tests.
So if we change API, we can just change single function and then regenerate all instances.
Apparently, mysql-haskell
can't read two (and more) files in a row without throwing the exception two times before it works on the third run. So the dirty hack is to add the function which will take the list of files, read it and concatenate together as one big text and after run the MySQL.executeMany_
on that and hope that it won't fail.
Subtask of #49
Just as pure function for now (to make things easier).
Using Generic
capabilities
MySql doesn't have booleans. So Bool
is Int64
0 or 1 ๐คทโโ๏ธ
And, probably, implement Show
instance using this function?..
Blocked by #6
Currently when we failed to parse row we specify the id of the column that was failed to parse. But we can go even further. We can use ColumnDef
to tell even more about failing column. The datatype is quite useful:
We have list of all column definitions here:
We can do this by adding [ColumnDef]
field to the MatcherState
and then use it later when we throw error.
Subtask of #49
Add this function:
queryNamed :: ... => MySQLConn -> Query -> [NamedParam] -> m [row]
using extractNames
from MySql.Named
as a black box.
Subtask on #49
Just like in sqlite-simple
library.
Probably can think of human-readable name as well (to be able to add it to custom Prelude
).
We will have single table with columns of different types (INT, TEXT, Double, TIMESTAMP) so later we can write tests. And, also, add PRIMARY KEY and stuff like that.
Subtask of #49
Just to test our functions
Should be for TIMESTAMP column type
They should take MySQLConnection
as an argument so we could reuse them later with our WithDb
constraint.
Useful for debugging purposes
To not depend on mysql-haskell
library and be able to connect and execute queries without bringing extra dependency.
To give better error messages.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.