Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul type parsers #6473

Closed
felixfbecker opened this issue Aug 19, 2016 · 7 comments
Closed

Overhaul type parsers #6473

felixfbecker opened this issue Aug 19, 2016 · 7 comments
Assignees
Labels
stale type: refactor For issues and PRs. Things that improve the code readability, maintainability, testability, etc.

Comments

@felixfbecker
Copy link
Contributor

felixfbecker commented Aug 19, 2016

Prerequisite for #6290
@janmeier Can you do this? I think it's your code

Library support:

The benefit of query-level type parsers are that parse() can be an instance method of the data type.

@felixfbecker felixfbecker added this to the 4.0 milestone Aug 19, 2016
@janmeier janmeier self-assigned this Aug 22, 2016
@felixfbecker felixfbecker changed the title Use connection-level type parser for postgres Use connection-level type parsers Aug 26, 2016
@felixfbecker felixfbecker added the type: refactor For issues and PRs. Things that improve the code readability, maintainability, testability, etc. label Aug 26, 2016
@felixfbecker felixfbecker changed the title Use connection-level type parsers Overhaul type parsers Aug 26, 2016
@felixfbecker
Copy link
Contributor Author

@janmeier How are data type parsers set in tedious and sqlite?

I would really like to make parse() an instance method of the data types for consistency, so they can access this.options and to have specific parsers per column (for example in one column the JSON should be parsed as one specific class, in the other column it should be a different class). But that is not possible with connection level parsers. The solution would be to handle the data type parsing in sequelize itself, eg take the value from the library and convert it again. This might actually simplify the code.

Raw queries would return the raw values from the library of course.

@janmeier
Copy link
Member

sqlite https://github.com/sequelize/sequelize/blob/master/lib/dialects/sqlite/query.js#L167-L181
mssql https://github.com/sequelize/sequelize/blob/master/lib/dialects/mssql/query.js#L91-L105

I definitely see the benefits of tying the data type parse directly to models, since we would be able to do a lot more.

I do however think it might be a problem if we don't also hook into raw queries. For example, dates are not even date objects in sqlite by default.

return new Date(date); // We already have a timezone stored in the string
.

I definitely agree that a type system tie up to models would be more powerful though. And if we provide the option of passing the model to a raw query and using the type parsers from the, it might be a good compromise

@felixfbecker
Copy link
Contributor Author

Yes, we need to take raw queries into account. But stringify() is already a prototype method of the data type, so how are raw INSERT queries handled at the moment? Calling DataType.prototype.stringify()? Then we could certainly do that for parse() aswell, we just have to make sure that options is set on the prototype with some sane defaults.

@janmeier
Copy link
Member

Currently raw inserts are handled by sql-string - As you've seen we already call out to datatypes a couple of places from there

@felixfbecker
Copy link
Contributor Author

I guess it's fine as long as we have options defined on the prototype. So basically do we agree on

  • removing parserStore
  • making parse() an instance method
    ?

For the postgres parsers I propose we just leave them at the default and then call our parsers on top of it.

@janmeier
Copy link
Member

Sounds good to me :)

@felixfbecker
Copy link
Contributor Author

nice, if you take these, I will do the custom type parsers.

@felixfbecker felixfbecker modified the milestone: 4.0 Nov 18, 2016
@stale stale bot added the stale label Jun 29, 2017
@stale stale bot closed this as completed Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale type: refactor For issues and PRs. Things that improve the code readability, maintainability, testability, etc.
Projects
None yet
Development

No branches or pull requests

2 participants