Closed sethreidnz closed 7 years ago
Thanks for the interest.
It does not work with MS SQL now but could be adapted pretty easily. I'll do this when I have some free time, but if you want to take a crack at it here's some starting points.
Primarily what we'll want to do is create a dialect base class and dialect implementations. Change Schema.ts
to reference the base class and have away to dynamically load the specific implementation based on config.
Schema.ts
changes
fieldTypeTranslations
needs to be augmented to come from the specific dialect. It's probably useful for the base to provide most common translations and then specific dialects can provide translations specific to that database. For example, int
, integer
, smallint
are pretty common and can go in base. geometry
is not common and would more likely be in the MySQL specific dialect.
fieldTypeSequelize
same as fieldTypeTranslations
. Since we'll need to provide more data, probably better to combine them into a single structure with keys and a value object that has the TypeScript type and Sequelize type as two separate attributes.
read
All of the read related functions should be moved to the dialect base class with more extension options for customization. This code doesn't really belong in the Schema file anyways. The goal would be to take parts that are specific to each dialect and make them into their own functions that can be overridden. For example, we wouldn't want to override all of read
but we would want to override the specific sql string we use to get the column information. Don't try to make sequelize-auto-ts
understand schema from every database, use the dialect to provide schema info in the format already expected. There are total of three places where there is sql in the read functions. All three should be separated out and the rest should work as is.
So if you want to take a go at it I'll be happy to review a fork when you want or answer questions. As long as you do it and implement both MySQL and MSSQL dialects, I'll be more than happy to merge your changes back in.
Sam
I would love to do it but I am under the pump at the moment (early stage start up going through funding round) however I might do it as a xmas period project as I think it would be really cool. Specifically since the Typescript community is more likely to come from a .MS background (well traditionally anyway).
Ill let you know if I do make a start however. I am pretty new to Typescript in general though so I'm not sure how fast/well I'd be able to help
Hi, although as above I said I don't really have time right now to implement the ideal thing (making your library work with MS SQL) how does one reference the types from Sequelize in typscript? For example if I wanted to create and interface or class that describes my data models I create in Sequelize how do I reference their data types?
For example if I have a model like this:
var Sequelize = require("sequelize");
module.exports = function (sequelize, DataTypes) {
var PropertyDetail = sequelize.define("PropertyDetail", {
id: {type: Sequelize.UUID, primaryKey: true},
buildingType: DataTypes.STRING,
numberOfBathrooms: DataTypes.INTEGER,
numberOfBedrooms: DataTypes.INTEGER,
numberOfCarParks: DataTypes.INTEGER
});
return PropertyDetail;
};
And want to create an interface for it how does that work? I'm sure it's obvious I just can't quite figure out how you do it..
Basically I want to be like:
class PropertyDetail{
id: Sequelize.UUID,
buildingType: DataTypes.STRING,
numberOfBathrooms: DataTypes.INTEGER,
numberOfBedrooms: DataTypes.INTEGER,
numberOfCarParks: DataTypes.INTEGER
}
And have that pass typescript compilation
Any updates on this one?
I don't have any plans to add support for other databases myself but will be happy to merge working pull requests and provide guidance to anyone working on it.
Thanks,
Sam
I realise this is not really an 'issue' but I would love to hear your thoughts. I am going to use msSQL and this library looks pretty cool