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
[looking for feedback] Reworking STRING & BINARY DataTypes #14259
Comments
DataTypes.STRING
DataTypes.STRING
Still working on this proposal and after further work on #14505, here is an updated/alternative proposal:
String DataType
Note: Dialects that do not support specifying a byte length on the text type could enforce it using a check constraint. VARCHAR max value of length arg:
Binary DataType
Note: Dialects that do not support specifying a byte length on the text type could enforce it using a check constraint. |
Sounds good! I guess we want to do this for v7 but in a future PR, right? Or do you want to tackle this in #14505 as well? (I'd prefer it in a future PR, but I can imagine that doing the same work twice is also not that efficient) |
Oh no definitely its own PR |
Another thing is that currently, I propose to keep I don't like the name, it's ambiguous (as can be seen by the fact that all other dialects have implemented it incorrectly). I propose to deprecate it & rename it to I've updated the table in my previous post |
In DB2, there is also |
DataTypes.STRING
DataTypes.STRING
, DataTypes.CHAR
, DataTypes.BLOB
, DataTypes.TEXT
@ephys as mentioned during the monthly, I'll try to look into this. Do you think the tables are near completion? |
In my opinion it's ready, but I'd love a thorough review so we don't need to introduce another breaking change in the future |
Another proposal because I can't make my mind up I found the previous one to be too complicated. This one should provide more control over which type is used, while still providing a common group of options that can be used everywhere. STRING DataType
SQL Server extensions
MySQL / MariaDB extensionsMySQL / MariaDB use
DB2 extensionsDB2 automatically uses
DB2 extensions
BINARY DataType
MySQL / MariaDB & DB2 extensionsMySQL / MariaDB use DB2 automatically uses
Footnotes |
DataTypes.STRING
, DataTypes.CHAR
, DataTypes.BLOB
, DataTypes.TEXT
DataTypes.STRING
, DataTypes.CHAR
, DataTypes.BLOB
, DataTypes.TEXT
DataTypes.STRING
, DataTypes.CHAR
, DataTypes.BLOB
, DataTypes.TEXT
DataTypes.STRING
, DataTypes.CHAR
, DataTypes.BLOB
, DataTypes.TEXT
, DataTypes.CITEXT
DataTypes.STRING
, DataTypes.CHAR
, DataTypes.BLOB
, DataTypes.TEXT
, DataTypes.CITEXT
My $0.02 is that
There is little justification for changing the current default behavior IMO. |
Thank you very much for taking the time to give your feedback :) You raise important issues that indicate that
Note though that I personally dislike the default length of 255 as I think devs should think about which length suits their column. Still, with all the changes we already have, I'm willing to drop this one Here is yet another design update:
Latest designSTRING DataType
CLOBThese are available in dialects that support Character Large Objects (Sometimes called TEXT, sometimes called CLOB. Equivalent of a BLOB for characters).
MySQL/MariaDB extensions
About NATIONALCurrent mssql implementation uses const sequelize = new Sequelize({
string: {
// Use .NATIONAL by default when using DataTypes.STRING
national: true,
},
}); Users can then opt out of using We should also add a const NVARCHAR = DataTypes.STRING.NATIONAL;
const User = sequelize.define('User', {
name: NVARCHAR.LENGTH(100),
}); BINARY DataType
While BLOBThese are available in dialects that support Binary Large Objects (BLOB).
Pending Questions
Footnotes |
First I was annoyed that I'm used to just use pg's Given that, I don't see pg's |
It's a very difficult balancing act between trying to have data types that mean (roughly) the same thing in all dialects, and have good defaults for each dialect. It's a headache. The design isn't set in stone yet. We're very much still debating this proposal
Note that you can reuse a configured data type like this: // datatypes.ts
export const STRING = DataTypes.STRING.MAX;
// user.model.ts
import { STRING } from './datatypes.js';
class User extends Model {
@Attribute(STRING)
declare username: string;
} |
One option to balance between having a default length for VARCHAR and encouraging developers to choose a reasonable size would be to make the default a Sequelize constructor option, and if that option is not provided, simple disallow the default constructor. That way not only do you increase the visibility of the fact that |
Goals
DataTypes.STRING.BINARY
generatesBINARY
in some dialects (instead ofVARBINARY
), andVARCHAR BINARY
in mysql, which are not equivalent.Proposition
DataTypes.STRING
based on the table below. AddDataTypes.BINARY
.DataTypes.CITEXT
,DataTypes.TEXT
,DataTypes.CHAR
,DataTypes.BLOB
Latest design
STRING DataType
STRING
VARCHAR(255)
VARCHAR(255)
VARCHAR(255)
TEXT
1VARCHAR(255)
VARCHAR2(255 CHAR)
VARCHAR(255)
STRING('max')
VARCHAR
VARCHAR(MAX)
TEXT
VARCHAR
STRING(256)
VARCHAR(256)
VARCHAR(256)
VARCHAR(256)
TEXT
1VARCHAR(256)
VARCHAR(256 CHAR)
VARCHAR(256)
STRING(256).FIXED
CHAR(256)
CHAR(256)
CHAR(256)
CHARACTER(256)
CHAR(256 CHAR)
STRING.FIXED.LENGTH(256)
CHAR(256)
CHAR(256)
CHAR(256)
CHARACTER(256)
CHAR(256 CHAR)
STRING.FIXED
STRING('max').FIXED
STRING(n).NATIONAL
NVARCHAR(n)
NVARCHAR(n)
NVARCHAR(n)
NVARCHAR(n)
STRING(n).FIXED.NATIONAL
NCHAR(n)
NCHAR(n)
NCHAR(n)
NCHAR(n)
STRING(n).INSENSITIVE
CITEXT
1TEXT COLLATE NOCASE
1STRING('max').INSENSITIVE
CITEXT
TEXT COLLATE NOCASE
STRING(n).COLLATION('name')
VARCHAR(n) COLLATE name
VARCHAR(n) COLLATE name
VARCHAR(n) COLLATE name
TEXT COLLATE name
VARCHAR(n) COLLATE name
VARCHAR2(n CHAR) COLLATE name
VARCHAR(n) COLLATE name
CLOB
These are available in dialects that support Character Large Objects (Sometimes called TEXT, sometimes called CLOB. Equivalent of a BLOB for characters).
STRING.CLOB('tiny')
TINYTEXT
STRING.CLOB
TEXT
1CLOB
STRING(n).CLOB
TEXT
1CLOB(n)
CLOB
1STRING(n).CLOB.NATIONAL
NCLOB(n)
NCLOB
1STRING.CLOB('medium')
MEDIUMTEXT
STRING.CLOB('long')
LONGTEXT
MySQL/MariaDB extensions
STRING(n).MYSQL_BIN_COLLATION
VARCHAR(n) BINARY
STRING(n).FIXED.MYSQL_BIN_COLLATION
CHAR(n) BINARY
About NATIONAL
Current mssql implementation uses
NVARCHAR
by default. In order to not require users to add.NATIONAL
everywhere, we could add the following global option:Users can then opt out of using
NATIONAL
by writingDataTypes.STRING.NATIONAL(false)
.We should also add a
LENGTH
option to allow users to re-use the sameSTRING
type with different lengths:BINARY DataType
BINARY
BINARY('max')
BYTEA
VARBINARY(MAX)
BLOB
LONG RAW
VARBINARY
BINARY(256)
BYTEA
2VARBINARY(256)
VARBINARY(256)
BLOB
2VARBINARY(256)
RAW(256)
VARBINARY(256)
BINARY(256).FIXED
BINARY(256)
BINARY(256)
BINARY(256)
BINARY.FIXED
BINARY.LENGTH(8000)
BYTEA
2VARBINARY(8000)
VARBINARY(8000)
BLOB
2VARBINARY(8000)
RAW(8000)
VARBINARY(8000)
While
STRING
defaults to 255 characters because it's a commonly used type,BINARY
requires an explicit length.,BLOB
These are available in dialects that support Binary Large Objects (BLOB).
BINARY.BLOB('tiny')
TINYBLOB
BINARY.BLOB
BLOB
BLOB
BINARY(256).BLOB
BLOB
2BLOB(256)
BLOB
2BINARY.BLOB('medium')
MEDIUMBLOB
BINARY.BLOB('long')
LONGBLOB
BINARY(256).BLOB('long')
LONGBLOB
2Pending Questions
VARCHAR(MAX)
more suited toSTRING.CLOB
orSTRING('max')
?STRING.INSENSITIVE
? It's better to use a collation thanCITEXT
for this. Maybe rename toSTRING.CITEXT
for postgres? Or keepCITEXT
a separate class?Footnotes
String length check constraint ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
Byte Count check constraint ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7
The text was updated successfully, but these errors were encountered: