Update dependency drizzle-orm to ^0.32.0 #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^0.28.5->^0.32.0Release Notes
drizzle-team/drizzle-orm (drizzle-orm)
v0.32.0Compare Source
Release notes for
drizzle-orm@0.32.0anddrizzle-kit@0.23.0New Features
🎉 MySQL
$returningId()functionMySQL itself doesn't have native support for
RETURNINGafter usingINSERT. There is only one way to do it forprimary keyswithautoincrement(orserial) types, where you can accessinsertIdandaffectedRowsfields. We've prepared an automatic way for you to handle such cases with Drizzle and automatically receive all inserted IDs as separate objectsAlso with Drizzle, you can specify a
primary keywith$defaultfunction that will generate custom primary keys at runtime. We will also return those generated keys for you in the$returningId()call🎉 PostgreSQL Sequences
You can now specify sequences in Postgres within any schema you need and define all the available properties
Example
🎉 PostgreSQL Identity Columns
Source: As mentioned, the
serialtype in Postgres is outdated and should be deprecated. Ideally, you should not use it.Identity columnsare the recommended way to specify sequences in your schema, which is why we are introducing theidentity columnsfeatureExample
You can specify all properties available for sequences in the
.generatedAlwaysAsIdentity()function. Additionally, you can specify custom names for these sequencesPostgreSQL docs reference.
🎉 PostgreSQL Generated Columns
You can now specify generated columns on any column supported by PostgreSQL to use with generated columns
Example with generated column for
tsvectorIn case you don't need to reference any columns from your table, you can use just
sqltemplate or astring🎉 MySQL Generated Columns
You can now specify generated columns on any column supported by MySQL to use with generated columns
You can specify both
storedandvirtualoptions, for more info you can check MySQL docsAlso MySQL has a few limitation for such columns usage, which is described here
Drizzle Kit will also have limitations for
pushcommand:You can't change the generated constraint expression and type using
push. Drizzle-kit will ignore this change. To make it work, you would need todrop the column,push, and thenadd a column with a new expression. This was done due to the complex mapping from the database side, where the schema expression will be modified on the database side and, on introspection, we will get a different string. We can't be sure if you changed this expression or if it was changed and formatted by the database. As long as these are generated columns andpushis mostly used for prototyping on a local database, it should be fast todropandcreategenerated columns. Since these columns aregenerated, all the data will be restoredgenerateshould have no limitationsExample
In case you don't need to reference any columns from your table, you can use just
sqltemplate or astringin.generatedAlwaysAs()🎉 SQLite Generated Columns
You can now specify generated columns on any column supported by SQLite to use with generated columns
You can specify both
storedandvirtualoptions, for more info you can check SQLite docsAlso SQLite has a few limitation for such columns usage, which is described here
Drizzle Kit will also have limitations for
pushandgeneratecommand:You can't change the generated constraint expression with the stored type in an existing table. You would need to delete this table and create it again. This is due to SQLite limitations for such actions. We will handle this case in future releases (it will involve the creation of a new table with data migration).
You can't add a
storedgenerated expression to an existing column for the same reason as above. However, you can add avirtualexpression to an existing column.You can't change a
storedgenerated expression in an existing column for the same reason as above. However, you can change avirtualexpression.You can't change the generated constraint type from
virtualtostoredfor the same reason as above. However, you can change fromstoredtovirtual.New Drizzle Kit features
🎉 Migrations support for all the new orm features
PostgreSQL sequences, identity columns and generated columns for all dialects
🎉 New flag
--forcefordrizzle-kit pushYou can auto-accept all data-loss statements using the push command. It's only available in CLI parameters. Make sure you always use it if you are fine with running data-loss statements on your database
🎉 New
migrationsflagprefixYou can now customize migration file prefixes to make the format suitable for your migration tools:
indexis the default type and will result in0001_name.sqlfile names;supabaseandtimestampare equal and will result in20240627123900_name.sqlfile names;unixwill result in unix seconds prefixes1719481298_name.sqlfile names;nonewill omit the prefix completely;Example: Supabase migrations format
v0.31.4Compare Source
v0.31.3Compare Source
Bug fixed
New Prisma-Drizzle extension
For more info, check docs: https://orm.drizzle.team/docs/prisma
v0.31.2Compare Source
🎉 Added support for TiDB Cloud Serverless driver:
v0.31.1Compare Source
New Features
Live Queries 🎉
As of
v0.31.1Drizzle ORM now has native support for Expo SQLite Live Queries!We've implemented a native
useLiveQueryReact Hook which observes necessary database changes and automatically re-runs database queries. It works with both SQL-like and Drizzle Queries:We've intentionally not changed the API of ORM itself to stay with conventional React Hook API, so we have
useLiveQuery(databaseQuery)as opposed todb.select().from(users).useLive()ordb.query.users.useFindMany()We've also decided to provide
data,errorandupdatedAtfields as a result of hook for concise explicit error handling following practices ofReact QueryandElectric SQLv0.31.0Compare Source
Breaking changes
PostgreSQL indexes API was changed
The previous Drizzle+PostgreSQL indexes API was incorrect and was not aligned with the PostgreSQL documentation. The good thing is that it was not used in queries, and drizzle-kit didn't support all properties for indexes. This means we can now change the API to the correct one and provide full support for it in drizzle-kit
Previous API
.on..usingand.onin our case are the same thing, so the API is incorrect here..asc(),.desc(),.nullsFirst(), and.nullsLast()should be specified for each column or expression on indexes, but not on an index itself.Current API
New Features
🎉 "pg_vector" extension support
You can now specify indexes for
pg_vectorand utilizepg_vectorfunctions for querying, ordering, etc.Let's take a few examples of
pg_vectorindexes from thepg_vectordocs and translate them to DrizzleL2 distance, Inner product and Cosine distance
L1 distance, Hamming distance and Jaccard distance - added in pg_vector 0.7.0 version
For queries, you can use predefined functions for vectors or create custom ones using the SQL template operator.
You can also use the following helpers:
If
pg_vectorhas some other functions to use, you can replicate implimentation from existing one we have. Here is how it can be doneName it as you wish and change the operator. This example allows for a numbers array, strings array, string, or even a select query. Feel free to create any other type you want or even contribute and submit a PR
Examples
Let's take a few examples of
pg_vectorqueries from thepg_vectordocs and translate them to Drizzle🎉 New PostgreSQL types:
point,lineYou can now use
pointandlinefrom PostgreSQL Geometric TypesType
pointhas 2 modes for mappings from the database:tupleandxy.tuplewill be accepted for insert and mapped on select to a tuple. So, the database Point(1,2) will be typed as [1,2] with drizzle.xywill be accepted for insert and mapped on select to an object with x, y coordinates. So, the database Point(1,2) will be typed as{ x: 1, y: 2 }with drizzleType
linehas 2 modes for mappings from the database:tupleandabc.tuplewill be accepted for insert and mapped on select to a tuple. So, the database Line{1,2,3} will be typed as [1,2,3] with drizzle.abcwill be accepted for insert and mapped on select to an object with a, b, and c constants from the equationAx + By + C = 0. So, the database Line{1,2,3} will be typed as{ a: 1, b: 2, c: 3 }with drizzle.🎉 Basic "postgis" extension support
geometrytype from postgis extension:mode
Type
geometryhas 2 modes for mappings from the database:tupleandxy.tuplewill be accepted for insert and mapped on select to a tuple. So, the database geometry will be typed as [1,2] with drizzle.xywill be accepted for insert and mapped on select to an object with x, y coordinates. So, the database geometry will be typed as{ x: 1, y: 2 }with drizzletype
The current release has a predefined type:
point, which is thegeometry(Point)type in the PostgreSQL PostGIS extension. You can specify any string there if you want to use some other typeDrizzle Kit updates:
drizzle-kit@0.22.0New Features
🎉 Support for new types
Drizzle Kit can now handle:
pointandlinefrom PostgreSQLvectorfrom the PostgreSQLpg_vectorextensiongeometryfrom the PostgreSQLPostGISextension🎉 New param in drizzle.config -
extensionsFiltersThe PostGIS extension creates a few internal tables in the
publicschema. This means that if you have a database with the PostGIS extension and usepushorintrospect, all those tables will be included indiffoperations. In this case, you would need to specifytablesFilter, find all tables created by the extension, and list them in this parameter.We have addressed this issue so that you won't need to take all these steps. Simply specify
extensionsFilterswith the name of the extension used, and Drizzle will skip all the necessary tables.Currently, we only support the
postgisoption, but we plan to add more extensions if they create tables in thepublicschema.The
postgisoption will skip thegeography_columns,geometry_columns, andspatial_ref_systablesImprovements
Update zod schemas for database credentials and write tests to all the positive/negative cases
Normilized SQLite urls for
libsqlandbetter-sqlite3driversThose drivers have different file path patterns, and Drizzle Kit will accept both and create a proper file path format for each
Updated MySQL and SQLite index-as-expression behavior
In this release MySQL and SQLite will properly map expressions into SQL query. Expressions won't be escaped in string but columns will be
Bug Fixes
How
pushandgenerateworks for indexesLimitations
You should specify a name for your index manually if you have an index on at least one expression
Example
Push won't generate statements if these fields(list below) were changed in an existing index:
.on()and.using().where()statements.op()on columnsIf you are using
pushworkflows and want to change these fields in the index, you would need to:For the
generatecommand,drizzle-kitwill be triggered by any changes in the index for any property in the new drizzle indexes API, so there are no limitations here.v0.30.10Compare Source
New Features
🎉
.if()function added to all WHERE expressionsSelect all users after cursors if a cursor value was provided
Bug Fixes
.all,.values,.executefunctions in AWS DataAPIv0.30.9Compare Source
setWhereandtargetWherefields to.onConflictDoUpdate()config in SQLite instead of singlewherefielddb._.fullSchemav0.30.8Compare Source
migrate()function to use batch API (#2137)whereclause in Postgres.onConflictDoUpdatemethod intosetWhereandtargetWhereclauses, to support bothwherecases inon conflict ...clause (fixes #1628, #1302 via #2056)whereclause in Postgres.onConflictDoNothingmethod, as it was placed in a wrong spot (fixes #1628 via #2056)Thanks @hugo082 and @livingforjesus!
v0.30.7Compare Source
Bug fixes
@vercel/postgrespackageneondrivers - #1542v0.30.6Compare Source
New Features
🎉 PGlite driver Support
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 2.6mb gzipped.
It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun) or indexedDB (Browser).
Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM.
Usage Example
There are currently 2 limitations, that should be fixed on Pglite side:
Attempting to refresh a materialised view throws error
Attempting to SET TIME ZONE throws error
v0.30.5Compare Source
New Features
🎉
$onUpdatefunctionality for PostgreSQL, MySQL and SQLiteAdds a dynamic update value to the column.
The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
If no
default(or$defaultFn) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.Fixes
Thanks @Angelelz and @gabrielDonnantuoni!
v0.30.4Compare Source
New Features
🎉 xata-http driver support
According their official website, Xata is a Postgres data platform with a focus on reliability, scalability, and developer experience. The Xata Postgres service is currently in beta, please see the Xata docs on how to enable it in your account.
Drizzle ORM natively supports both the
xatadriver withdrizzle-orm/xatapackage and thepostgresorpgdrivers for accessing a Xata Postgres database.The following example use the Xata generated client, which you obtain by running the xata init CLI command.
You can also connect to Xata using
pgorpostgres.jsdriversv0.30.3Compare Source
db.execute(...)) to batch API in Neon HTTP driver@neondatabase/serverlessHTTP driver types issue (#1945, neondatabase/serverless#66).run()result (https://github.com/drizzle-team/drizzle-orm/pull/2038)v0.30.2Compare Source
Improvements
LibSQL migrations have been updated to utilize batch execution instead of transactions. As stated in the documentation, LibSQL now supports batch operations
Bug fixed
v0.30.1Compare Source
New Features
🎉 OP-SQLite driver Support
Usage Example
For more usage and setup details, please check our op-sqlite docs
Bug fixes
v0.30.0Compare Source
Breaking Changes
The Postgres timestamp mapping has been changed to align all drivers with the same behavior.
❗ We've modified the
postgres.jsdriver instance to always return strings for dates, and then Drizzle will provide you with either strings of mapped dates, depending on the selectedmode. The only issue you may encounter is that once you provide the `postgres.js`` driver instance inside Drizzle, the behavior of this object will change for dates, which will always be strings.We've made this change as a minor release, just as a warning, that:
If you were using timestamps and were waiting for a specific response, the behavior will now be changed.
When mapping to the driver, we will always use
.toISOStringfor both timestamps with timezone and without timezone.If you were using the
postgres.jsdriver outside of Drizzle, allpostgres.jsclients passed to Drizzle will have mutated behavior for dates. All dates will be strings in the response.Parsers that were changed for
postgres.js.Ideally, as is the case with almost all other drivers, we should have the possibility to mutate mappings on a per-query basis, which means that the driver client won't be mutated. We will be reaching out to the creator of the
postgres.jslibrary to inquire about the possibility of specifying per-query mapping interceptors and making this flow even better for all users.If we've overlooked this capability and it is already available with `postgres.js``, please ping us in our Discord!
A few more references for timestamps without and with timezones can be found in our docs
Bug fixed in this release
Big thanks to @Angelelz!
v0.29.5Compare Source
New Features
🎉 WITH UPDATE, WITH DELETE, WITH INSERT - thanks @L-Mario564
You can now use
WITHstatements with INSERT, UPDATE and DELETE statementsUsage examples
Generated SQL:
For more examples for all statements, check docs:
🎉 Possibility to specify custom schema and custom name for migrations table - thanks @g3r4n
By default, all information about executed migrations will be stored in the database inside the
__drizzle_migrationstable,and for PostgreSQL, inside the
drizzleschema. However, you can configure where to store those records.To add a custom table name for migrations stored inside your database, you should use the
migrationsTableoptionUsage example
To add a custom schema name for migrations stored inside your database, you should use the
migrationsSchemaoptionUsage example
🎉 SQLite Proxy bacth and Relational Queries support
You can now use
.query.findFirstand.query.findManysyntax with sqlite proxy driverSQLite Proxy supports batch requests, the same as it's done for all other drivers. Check full docs
You will need to specify a specific callback for batch queries and handle requests to proxy server:
And then you can use
db.batch([])method, that will proxy all queriesv0.29.4Compare Source
New Features
🎉 Neon HTTP Batch
For more info you can check Neon docs
Example
Improvements
Thanks to the
database-jsandPlanetScaleteams, we have updated the default behavior and instances ofdatabase-js.As suggested by the
database-jscore team, you should use theClientinstance instead ofconnect():Previously our docs stated to use
connect()and only this function was can be passed to drizzle. In this realase we are adding support fornew Client()and deprecatingconnect(), by suggesting fromdatabase-jsteam. In this release you will see awarningwhen trying to passconnect()function result:Warning text
v0.29.3Compare Source
v0.29.2Compare Source
Fixes
ESLint Drizzle Plugin, v0.2.3
🎉 [ESLint] Add support for functions and improve error messages #1586 - thanks @ngregrichardson
New Drivers
🎉 Expo SQLite Driver is available
For starting with Expo SQLite Driver, you need to install
expo-sqliteanddrizzle-ormpackages.Then, you can use it like this:
If you want to use Drizzle Migrations, you need to update babel and metro configuration files.
babel-plugin-inline-importpackage.babel.config.jsandmetro.config.jsfiles.babel.config.js
module.exports = function(api) { api.cache(true); return { presets: ['babel-preset-expo'], + plugins: [["inline-import", { "extensions": [".sql"] }]] }; };metro.config.js
const { getDefaultConfig } = require('expo/metro-config'); /** @​type {import('expo/metro-config').MetroConfig} */ const config = getDefaultConfig(__dirname); +config.resolver.sourceExts.push('sql'); module.exports = config;drizzle.config.tsfile in your project root folder.After creating schema file and drizzle.config.ts file, you can generate migrations like this:
Then you need to import
migrations.jsfile in yourApp.tsxfile from./drizzlefolder and use hookuseMigrationsormigratefunction.v0.29.1Compare Source
Fixes
New Features/Helpers
🎉 Detailed JSDoc for all query builders in all dialects - thanks @realmikesolo
You can now access more information, hints, documentation links, etc. while developing and using JSDoc right in your IDE. Previously, we had them only for filter expressions, but now you can see them for all parts of the Drizzle query builder
🎉 New helpers for aggregate functions in SQL - thanks @L-Mario564
Here is a list of functions and equivalent using
sqltemplatecount
countDistinct
avg
avgDistinct
sum
sumDistinct
max
min
New Packages
🎉 ESLint Drizzle Plugin
For cases where it's impossible to perform type checks for specific scenarios, or where it's possible but error messages would be challenging to understand, we've decided to create an ESLint package with recommended rules. This package aims to assist developers in handling crucial scenarios during development
Install
You can install those packages for typescript support in your IDE
Usage
Create a
.eslintrc.ymlfile, adddrizzleto theplugins, and specify the rules you want to use. You can find a list of all existing rules belowAll config
This plugin exports an
allconfig that makes use of all rules (except for deprecated ones).At the moment,
allis equivalent torecommendedRules
enforce-delete-with-where: Enforce using
deletewith the.where()clause in the.delete()statement. Most of the time, you don't need to delete all rows in the table and require some kind ofWHEREstatements.Error Message:
Optionally, you can define a
drizzleObjectNamein the plugin options that accept astringorstring[]. This is useful when you have objects or classes with a delete method that's not from Drizzle. Such adeletemethod will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object:Example, config 1:
Example, config 2:
enforce-update-with-where: Enforce using
updatewith the.where()clause in the.update()statement. Most of the time, you don't need to update all rows in the table and require some kind ofWHEREstatements.Error Message:
Optionally, you can define a
drizzleObjectNamein the plugin options that accept astringorstring[]. This is useful when you have objects or classes with a delete method that's not from Drizzle. Such asupdatemethod will trigger the ESLint rule. To avoid that, you can define the name of the Drizzle object that you use in your codebase (like db) so that the rule would only trigger if the delete method comes from this object:Example, config 1:
Example, config 2:
v0.29.0Compare Source
New Features
🎉 MySQL
unsignedoption for bigintYou can now specify
bigint unsignedtypeRead more in docs
🎉 Improved query builder types
Starting from
0.29.0by default, as all the query builders in Drizzle try to conform to SQL as much as possible, you can only invoke most of the methods once. For example, in a SELECT statement there might only be one WHERE clause, so you can only invoke .where() once:This behavior is useful for conventional
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.