You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Jaroslav Málek, Psycho Path, Ragnor Comerford, Johannes Schobel, Peter Pistorius, Javier Rojo, Matt Mueller, Alexander Hörl, Martin Krolikowski, Tanguy Krotoff and 33 more
Reacted by Aakash Kag, 장재영 and Avery Morin
Reacted by Ragnor Comerford, Javier Rojo, Sean Matheson, Matt Mueller, Filip Stefansson, Jan Schmidt, Vamshi krishna, Cristian Rosescu, Alex Vilchis, Aakash Kag and 1 more
I would also love to see types for varchar(x), smallint, longtext and so on. If a respective database does not support these types, it should "fallback" to the most appropriate type (i.e., smallint -> int.
Can we (community) participate and support you in implementing such Grammars for the different Database Engines? If so, i can surely create such mappings and provide a PR? Would love to contribute to this awesome project!
All the best,
Johannes
Reacted by Cristian Rosescu, Grzegorz Widła and Jack Baude
@johannesschobel it seems from these grammar files that they still provide common core types, just abstract over them (e.g. jsonb maps to text in sqlite).
Are there grammars that don't implement certain features where the database can't properly store the data type? I guess I'm wondering if this is a common, shared interface or it's database-specific.
The Grammar files i linked above, are some kind of "mapping" for these Laravel types. That means, that laravel, for example, provides types (i.e., json) that may not be supported by your chosen database system (sqlite, mysql, ...). This "mapping" is then handled by the underlying grammar file.
I think, the grammars implement a certain interface where all these Laravel Types are defined and then are implemented in the concrete grammar.. But not sure
I hope this helps?! Do you require further information?
@johannesschobel got it. thanks for clarifying, so in a sense they "upgrade" databases by adding features (e.g. jsonb for sqlite) . This works if all your database clients understand this agreement.
What I was curious about is if Laravel changes the migration API based on the database. So for example, they remove $table->jsonb if you're working with an SQLite database. This is more what we are considering.
We could always add more core datatypes to improve granularity and maybe we should. But it's a tradeoff. More datatypes means more surface area to "upgrade" for other databases. It also means that if we add a new core datatype tomorrow, we'll have to upgrade all datasources to support it.
thanks again for your reply on this. In some kind of way, Laravel enables new datatypes for underlying databases, yes. However, from 5.0 till 5.8 version (about 4 years) they did not change those Laravel Types - they only added new features (e.g., $table->json) when features where supported in a stable way from the database engines or can be mapped to "more basic datatypes" (i.e., Text) if no appropriate better type exist.
I really like the Laravel approach, as it - basically - is just an additional mapper / abstraction layer for the database types. This makes it incredibly easy to just add new databases "on the go". Changes to these grammars are quite limited (you can take a look at the git history of such files).
It is debatable, if all features provided by Laravel Grammars should be "ported" or not (i.e., naming conventions for index, ...) or if Prisma just takes the idea of mapping internal types to database specific types. Those grammars could also be extended quite easily if you have the need to specify a convention for naming your index structures...
Further, i don't think, that the Laravel Migration API changed significantly over time. Nevertheless, even if you would change your migration idea, you can still "correct" it in the grammars, right? 😆
i think, that each specific Grammar (i.e., PostgreSQLGrammar, SQLiteGrammar) should extend a BaseGrammar, which may implement a common interface.
The abstract BaseGrammar could have some "default one-fits-all" mappings. For example, the BaseGrammar could map the Prisma internal datatype JSON by default to a TEXT datatype in the database. However, PostgreSQL offers a "native json support", therefore this "mapping method" may be overwritten in the PostgreSQLGrammar to map it to JSON instead.
I think, i would add some kind of getFallbackType() method in the BaseGrammar which is extended by all other database-specific grammars.
This fallbackType returns, for example text as default type... Of course, this fallback Type can be overwritten for a specific implementation (i.e, the PostgreSQLGrammar may use LargeText as fallbackType, while SQLiteGrammar uses Text).
If, for example, the developer defines IPAddress or Polygon as "Prisma Datatype, and respective Datatype is not defined for the database, i would fallback to the fallbackType. For PostgreSQL this would be LargeText` for example.
At a later point in time, you could just add the getIPAddressType() method to the BaseGrammar or whatever specific grammar and map it to a proper database field type. If, for example, SQLite still does not support geo types, just omit it - it will then fallback to the default..
Activity
johannesschobel commentedon Sep 24, 2019
I would also love to see types for
varchar(x),smallint,longtextand so on. If a respective database does not support these types, it should "fallback" to the most appropriate type (i.e.,smallint -> int.In Laravel (PHP) they follow a similar approach as can be seen here in the docs:
https://laravel.com/docs/5.8/migrations#creating-columns
They just map to the "database equivalent of FLOAT" (or whatever).
In the grammars for the database engines (i.e., postgres, mysql, ...) this is handled as follows (example for
MediumInteger)PostgreSQL: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php#L487-L496
MySQL: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php#L501-L510
SQLite: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php#L484-L493
What do you think?
Can we (community) participate and support you in implementing such
Grammarsfor the different Database Engines? If so, i can surely create such mappings and provide a PR? Would love to contribute to this awesome project!All the best,
Johannes
matthewmueller commentedon Oct 2, 2019
@johannesschobel it seems from these grammar files that they still provide common core types, just abstract over them (e.g. jsonb maps to text in sqlite).
Are there grammars that don't implement certain features where the database can't properly store the data type? I guess I'm wondering if this is a common, shared interface or it's database-specific.
johannesschobel commentedon Oct 2, 2019
In Laravel, you have to write "Migration Files", where you define your database structure. In this migration files, you can add fields and define respective types (i.e.,
json,string,integer, and so on.. )You can take a look at how to create a migration here: https://laravel.com/docs/5.8/migrations#creating-columns
The
Grammarfiles i linked above, are some kind of "mapping" for theseLaraveltypes. That means, that laravel, for example, provides types (i.e.,json) that may not be supported by your chosen database system (sqlite, mysql, ...). This "mapping" is then handled by the underlying grammar file.I think, the grammars implement a certain interface where all these
Laravel Typesare defined and then are implemented in the concrete grammar.. But not sureI hope this helps?! Do you require further information?
matthewmueller commentedon Oct 2, 2019
@johannesschobel got it. thanks for clarifying, so in a sense they "upgrade" databases by adding features (e.g. jsonb for sqlite) . This works if all your database clients understand this agreement.
What I was curious about is if Laravel changes the migration API based on the database. So for example, they remove
$table->jsonbif you're working with an SQLite database. This is more what we are considering.We could always add more core datatypes to improve granularity and maybe we should. But it's a tradeoff. More datatypes means more surface area to "upgrade" for other databases. It also means that if we add a new core datatype tomorrow, we'll have to upgrade all datasources to support it.
tomhoule commentedon Oct 2, 2019
See this comment https://github.com/prisma/lift/issues/116#issuecomment-537534050 for a case where we could need what is currently one core data type (
String) to two database column types (varcharandtext) due to database limitations.johannesschobel commentedon Oct 4, 2019
Dear @matthewmueller ,
thanks again for your reply on this. In some kind of way,
Laravelenables new datatypes for underlying databases, yes. However, from 5.0 till 5.8 version (about 4 years) they did not change thoseLaravel Types- they only added new features (e.g.,$table->json) when features where supported in a stable way from the database engines or can be mapped to "more basic datatypes" (i.e.,Text) if no appropriate better type exist.I really like the
Laravelapproach, as it - basically - is just an additional mapper / abstraction layer for the database types. This makes it incredibly easy to just add new databases "on the go". Changes to these grammars are quite limited (you can take a look at the git history of such files).It is debatable, if all features provided by
Laravel Grammarsshould be "ported" or not (i.e., naming conventions for index, ...) or ifPrismajust takes the idea of mapping internal types to database specific types. Those grammars could also be extended quite easily if you have the need to specify a convention for naming your index structures...Further, i don't think, that the
Laravel MigrationAPI changed significantly over time. Nevertheless, even if you would change your migration idea, you can still "correct" it in the grammars, right? 😆matthewmueller commentedon Oct 4, 2019
@johannesschobel Would you prefer these "upgrades" versus a grammar that's specific to the database?
For example, you could also have a grammar that doesn't implement
$table->jsonfor SQLite, but does for Postgres.Would you see this as being an improvement or a step backwards?
johannesschobel commentedon Oct 4, 2019
i think, that each specific
Grammar(i.e.,PostgreSQLGrammar,SQLiteGrammar) should extend aBaseGrammar, which may implement a common interface.The abstract
BaseGrammarcould have some "default one-fits-all" mappings. For example, theBaseGrammarcould map thePrisma internal datatype JSONby default to aTEXTdatatype in the database. However,PostgreSQLoffers a "native json support", therefore this "mapping method" may be overwritten in thePostgreSQLGrammarto map it toJSONinstead.matthewmueller commentedon Oct 4, 2019
@johannesschobel what would you do for very postgres-specific types and extensions like
polygon,ipaddress&citext?johannesschobel commentedon Oct 4, 2019
I think, i would add some kind of
getFallbackType()method in theBaseGrammarwhich is extended by all other database-specific grammars.This fallbackType returns, for example
textas default type... Of course, this fallback Type can be overwritten for a specific implementation (i.e, thePostgreSQLGrammarmay useLargeTextas fallbackType, whileSQLiteGrammarusesText).If, for example, the developer defines
IPAddressorPolygonas "Prisma Datatype, and respective Datatype is not defined for the database, i would fallback to thefallbackType. For PostgreSQL this would beLargeText` for example.At a later point in time, you could just add the
getIPAddressType()method to theBaseGrammaror whatever specific grammar and map it to a proper database field type. If, for example,SQLitestill does not supportgeotypes, just omit it - it will then fallback to the default..What do you think?
[-]Support for custom types[/-][+]EPIC: Support for custom types[/+][-]EPIC: Support for custom types[/-][+]EPIC: Support for native database types[/+]ctrlplusb commentedon Dec 18, 2019
I like the idea of being able to support underlying native types.
I saw an example of a cool idea somewhere that would provide a lot more flexibility in this regard.
I really like this derived type idea. Something to keep in mind when spec'ing.
26 remaining items
matthewmueller commentedon Aug 27, 2020
Thanks for the lively discussion everyone! Closing in favor of #3447.
willin commentedon Sep 3, 2020
@mavilein which version to support? using v2.6.0 now, found not yet.
pantharshit00 commentedon Sep 3, 2020
@willin The work is still ongoing and the discussion from this issue was summarised on #3447 and that issue is now tracking this
poorvi-vaish commentedon Jun 1, 2023
can we use Buffer data type for images?
janpio commentedon Jun 7, 2023
Please open a discussion for this question @poorvi-vaish. Thank you.