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.0
Release Notes
drizzle-team/drizzle-orm (drizzle-orm)
v0.32.0
Compare Source
Release notes for
[email protected]
and[email protected]
New Features
🎉 MySQL
$returningId()
functionMySQL itself doesn't have native support for
RETURNING
after usingINSERT
. There is only one way to do it forprimary keys
withautoincrement
(orserial
) types, where you can accessinsertId
andaffectedRows
fields. 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 key
with$default
function 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
serial
type in Postgres is outdated and should be deprecated. Ideally, you should not use it.Identity columns
are the recommended way to specify sequences in your schema, which is why we are introducing theidentity columns
featureExample
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
tsvector
In case you don't need to reference any columns from your table, you can use just
sql
template 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
stored
andvirtual
options, 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
push
command: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 andpush
is mostly used for prototyping on a local database, it should be fast todrop
andcreate
generated columns. Since these columns aregenerated
, all the data will be restoredgenerate
should have no limitationsExample
In case you don't need to reference any columns from your table, you can use just
sql
template or astring
in.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
stored
andvirtual
options, 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
push
andgenerate
command: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
stored
generated expression to an existing column for the same reason as above. However, you can add avirtual
expression to an existing column.You can't change a
stored
generated expression in an existing column for the same reason as above. However, you can change avirtual
expression.You can't change the generated constraint type from
virtual
tostored
for the same reason as above. However, you can change fromstored
tovirtual
.New Drizzle Kit features
🎉 Migrations support for all the new orm features
PostgreSQL sequences, identity columns and generated columns for all dialects
🎉 New flag
--force
fordrizzle-kit push
You 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
migrations
flagprefix
You can now customize migration file prefixes to make the format suitable for your migration tools:
index
is the default type and will result in0001_name.sql
file names;supabase
andtimestamp
are equal and will result in20240627123900_name.sql
file names;unix
will result in unix seconds prefixes1719481298_name.sql
file names;none
will omit the prefix completely;Example: Supabase migrations format
v0.31.4
Compare Source
v0.31.3
Compare Source
Bug fixed
New Prisma-Drizzle extension
For more info, check docs: https://orm.drizzle.team/docs/prisma
v0.31.2
Compare Source
🎉 Added support for TiDB Cloud Serverless driver:
v0.31.1
Compare Source
New Features
Live Queries 🎉
As of
v0.31.1
Drizzle ORM now has native support for Expo SQLite Live Queries!We've implemented a native
useLiveQuery
React 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
,error
andupdatedAt
fields as a result of hook for concise explicit error handling following practices ofReact Query
andElectric SQL
v0.31.0
Compare 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
..using
and.on
in 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_vector
and utilizepg_vector
functions for querying, ordering, etc.Let's take a few examples of
pg_vector
indexes from thepg_vector
docs 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_vector
has 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_vector
queries from thepg_vector
docs and translate them to Drizzle🎉 New PostgreSQL types:
point
,line
You can now use
point
andline
from PostgreSQL Geometric TypesType
point
has 2 modes for mappings from the database:tuple
andxy
.tuple
will 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.xy
will 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
line
has 2 modes for mappings from the database:tuple
andabc
.tuple
will 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.abc
will 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
geometry
type from postgis extension:mode
Type
geometry
has 2 modes for mappings from the database:tuple
andxy
.tuple
will be accepted for insert and mapped on select to a tuple. So, the database geometry will be typed as [1,2] with drizzle.xy
will 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:
[email protected]
New Features
🎉 Support for new types
Drizzle Kit can now handle:
point
andline
from PostgreSQLvector
from the PostgreSQLpg_vector
extensiongeometry
from the PostgreSQLPostGIS
extension🎉 New param in drizzle.config -
extensionsFilters
The PostGIS extension creates a few internal tables in the
public
schema. This means that if you have a database with the PostGIS extension and usepush
orintrospect
, all those tables will be included indiff
operations. 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
extensionsFilters
with the name of the extension used, and Drizzle will skip all the necessary tables.Currently, we only support the
postgis
option, but we plan to add more extensions if they create tables in thepublic
schema.The
postgis
option will skip thegeography_columns
,geometry_columns
, andspatial_ref_sys
tablesImprovements
Update zod schemas for database credentials and write tests to all the positive/negative cases
Normilized SQLite urls for
libsql
andbetter-sqlite3
driversThose 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
push
andgenerate
works 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
push
workflows and want to change these fields in the index, you would need to:For the
generate
command,drizzle-kit
will 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.10
Compare Source
New Features
🎉
.if()
function added to all WHERE expressionsSelect all users after cursors if a cursor value was provided
Bug Fixes
.all
,.values
,.execute
functions in AWS DataAPIv0.30.9
Compare Source
setWhere
andtargetWhere
fields to.onConflictDoUpdate()
config in SQLite instead of singlewhere
fielddb._.fullSchema
v0.30.8
Compare Source
migrate()
function to use batch API (#2137)where
clause in Postgres.onConflictDoUpdate
method intosetWhere
andtargetWhere
clauses, to support bothwhere
cases inon conflict ...
clause (fixes #1628, #1302 via #2056)where
clause in Postgres.onConflictDoNothing
method, as it was placed in a wrong spot (fixes #1628 via #2056)Thanks @hugo082 and @livingforjesus!
v0.30.7
Compare Source
Bug fixes
@vercel/postgres
packageneon
drivers - #1542v0.30.6
Compare 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.5
Compare Source
New Features
🎉
$onUpdate
functionality 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.4
Compare 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
xata
driver withdrizzle-orm/xata
package and thepostgres
orpg
drivers 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
pg
orpostgres.js
driversv0.30.3
Compare Source
db.execute(...)
) to batch API in Neon HTTP driver@neondatabase/serverless
HTTP driver types issue (#1945, neondatabase/serverless#66).run()
result (https://github.com/drizzle-team/drizzle-orm/pull/2038)v0.30.2
Compare 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.1
Compare 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.0
Compare Source
Breaking Changes
The Postgres timestamp mapping has been changed to align all drivers with the same behavior.
❗ We've modified the
postgres.js
driver 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
.toISOString
for both timestamps with timezone and without timezone.If you were using the
postgres.js
driver outside of Drizzle, allpostgres.js
clients 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.js
library 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.5
Compare Source
New Features
🎉 WITH UPDATE, WITH DELETE, WITH INSERT - thanks @L-Mario564
You can now use
WITH
statements 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_migrations
table,and for PostgreSQL, inside the
drizzle
schema. 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
migrationsTable
optionUsage example
To add a custom schema name for migrations stored inside your database, you should use the
migrationsSchema
optionUsage example
🎉 SQLite Proxy bacth and Relational Queries support
You can now use
.query.findFirst
and.query.findMany
syntax 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.4
Compare Source
New Features
🎉 Neon HTTP Batch
For more info you can check Neon docs
Example
Improvements
Thanks to the
database-js
andPlanetScale
teams, we have updated the default behavior and instances ofdatabase-js
.As suggested by the
database-js
core team, you should use theClient
instance 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-js
team. In this release you will see awarning
when trying to passconnect()
function result:Warning text
v0.29.3
Compare Source
v0.29.2
Compare 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-sqlite
anddrizzle-orm
packages.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-import
package.babel.config.js
andmetro.config.js
files.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.ts
file 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.js
file in yourApp.tsx
file from./drizzle
folder and use hookuseMigrations
ormigrate
function.v0.29.1
Compare 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
sql
templatecount
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.yml
file, adddrizzle
to theplugins
, and specify the rules you want to use. You can find a list of all existing rules belowAll config
This plugin exports an
all
config that makes use of all rules (except for deprecated ones).At the moment,
all
is equivalent torecommended
Rules
enforce-delete-with-where: Enforce using
delete
with 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 ofWHERE
statements.Error Message:
Optionally, you can define a
drizzleObjectName
in the plugin options that accept astring
orstring[]
. This is useful when you have objects or classes with a delete method that's not from Drizzle. Such adelete
method 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
update
with 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 ofWHERE
statements.Error Message:
Optionally, you can define a
drizzleObjectName
in the plugin options that accept astring
orstring[]
. This is useful when you have objects or classes with a delete method that's not from Drizzle. Such asupdate
method 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.0
Compare Source
New Features
🎉 MySQL
unsigned
option for bigintYou can now specify
bigint unsigned
typeRead more in docs
🎉 Improved query builder types
Starting from
0.29.0
by 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.