[Snyk] Upgrade drizzle-orm from 0.30.10 to 0.31.2 #5
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 was automatically created by Snyk using the credentials of a real user.

Snyk has created this PR to upgrade drizzle-orm from 0.30.10 to 0.31.2.
ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.
The recommended version is 22 versions ahead of your current version.
The recommended version was released on a month ago.
Release notes
Package name: drizzle-orm
-
0.31.2 - 2024-06-07
-
import { connect } from '@ tidbcloud/serverless';
-
0.31.2-f9f4c2e - 2024-06-09
-
0.31.2-ee089d9 - 2024-07-06
-
0.31.2-c59440c - 2024-06-09
-
0.31.2-bd14b3f - 2024-06-07
-
0.31.2-b59e0a5 - 2024-06-11
-
0.31.2-b59b8f5 - 2024-07-08
-
0.31.2-b1c8d15 - 2024-06-09
-
0.31.2-aaea9bd - 2024-06-27
-
0.31.2-86ec973 - 2024-06-07
-
0.31.2-5b29cb4 - 2024-06-06
-
0.31.1 - 2024-06-04
import { useLiveQuery, drizzle } from 'drizzle-orm/expo-sqlite';
-
0.31.1-7a4cc2d - 2024-06-04
-
0.31.1-26a7171 - 2024-05-30
-
0.31.0 - 2024-05-31
- No way to define SQL expressions inside
)
// CREATE INDEX ON items USING hnsw (embedding vector_l2_ops);
// CREATE INDEX ON items USING hnsw (embedding vector_l1_ops);
import { l2Distance, l1Distance, innerProduct,
import { l2Distance } from 'drizzle-orm';
-
-
-
-
import { defineConfig } from 'drizzle-kit'
- support full set of SSL params in kit config, provide types from node:tls connection
import { defineConfig } from 'drizzle-kit'
import { defineConfig } from 'drizzle-kit'
-- before
- [BUG]: multiple constraints not added (only the first one is generated) - #2341
- Drizzle Studio: Error: Connection terminated unexpectedly - #435
- Unable to run sqlite migrations local - #432
- error: unknown option '--config' - #423
index().on(table.id, table.email) // will work well and name will be autogeneretaed
- expressions inside
- operator classes
- Comment out the index
- Push
- Uncomment the index and change those fields
- Push again
-
0.31.0-ef463e5 - 2024-05-29
-
0.31.0-e64a96d - 2024-05-22
-
0.31.0-c7963ca - 2024-05-23
-
0.31.0-a70b6ea - 2024-05-25
-
0.31.0-7a05232 - 2024-05-23
-
0.31.0-6df4b83 - 2024-05-29
-
0.31.0-61bc749 - 2024-05-30
-
0.30.10 - 2024-05-01
- Fixed internal mappings for sessions
from drizzle-orm GitHub release notes🎉 Added support for TiDB Cloud Serverless driver:
import { drizzle } from 'drizzle-orm/tidb-serverless';
const client = connect({ url: '...' });
const db = drizzle(client);
await db.select().from(...);
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:import { openDatabaseSync } from 'expo-sqlite/next';
import { users } from './schema';
import { Text } from 'react-native';
const expo = openDatabaseSync('db.db', { enableChangeListener: true }); // <-- enable change listeners
const db = drizzle(expo);
const App = () => {
// Re-renders automatically when data changes
const { data } = useLiveQuery(db.select().from(users));
// const { data, error, updatedAt } = useLiveQuery(db.query.users.findFirst());
// const { data, error, updatedAt } = useLiveQuery(db.query.users.findMany());
return <Text>{JSON.stringify(data)}</Text>;
};
export default App;
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 SQLBreaking 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
.with({ fillfactor: '70' })
// Second Example, with
.using()index('name')
.using('btree', table.column1.asc(), sql
lower(<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">table</span><span class="pl-kos">.</span><span class="pl-c1">column2</span><span class="pl-kos">}</span></span>), table.column1.op('text_ops')).where(sql``) // sql expression
.with({ fillfactor: '70' })
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
// CREATE INDEX ON items USING hnsw (embedding vector_ip_ops);
// CREATE INDEX ON items USING hnsw (embedding vector_cosine_ops);
const table = pgTable('items', {
embedding: vector('embedding', { dimensions: 3 })
}, (table) => ({
l2: index('l2_index').using('hnsw', table.embedding.op('vector_l2_ops'))
ip: index('ip_index').using('hnsw', table.embedding.op('vector_ip_ops'))
cosine: index('cosine_index').using('hnsw', table.embedding.op('vector_cosine_ops'))
}))
L1 distance, Hamming distance and Jaccard distance - added in pg_vector 0.7.0 version
// CREATE INDEX ON items USING hnsw (embedding bit_hamming_ops);
// CREATE INDEX ON items USING hnsw (embedding bit_jaccard_ops);
const table = pgTable('table', {
embedding: vector('embedding', { dimensions: 3 })
}, (table) => ({
l1: index('l1_index').using('hnsw', table.embedding.op('vector_l1_ops'))
hamming: index('hamming_index').using('hnsw', table.embedding.op('bit_hamming_ops'))
bit: index('bit_jaccard_index').using('hnsw', table.embedding.op('bit_jaccard_ops'))
}))
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:
cosineDistance, hammingDistance, jaccardDistance } from 'drizzle-orm'
l2Distance(table.column, [3, 1, 2]) // table.column <-> '[3, 1, 2]'
l1Distance(table.column, [3, 1, 2]) // table.column <+> '[3, 1, 2]'
innerProduct(table.column, [3, 1, 2]) // table.column <#> '[3, 1, 2]'
cosineDistance(table.column, [3, 1, 2]) // table.column <=> '[3, 1, 2]'
hammingDistance(table.column, '101') // table.column <~> '101'
jaccardDistance(table.column, '101') // table.column <%> '101'
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// SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;
db.select().from(items).orderBy(l2Distance(items.embedding, [3,1,2]))
// SELECT embedding <-> '[3,1,2]' AS distance FROM items;
db.select({ distance: l2Distance(items.embedding, [3,1,2]) })
// SELECT * FROM items ORDER BY embedding <-> (SELECT embedding FROM items WHERE id = 1) LIMIT 5;
const subquery = db.select({ embedding: items.embedding }).from(items).where(eq(items.id, 1));
db.select().from(items).orderBy(l2Distance(items.embedding, subquery)).limit(5)
// SELECT (embedding <#> '[3,1,2]') * -1 AS inner_product FROM items;
db.select({ innerProduct: sql
(<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-en">maxInnerProduct</span><span class="pl-kos">(</span><span class="pl-s1">items</span><span class="pl-kos">.</span><span class="pl-c1">embedding</span><span class="pl-kos">,</span> <span class="pl-kos">[</span><span class="pl-c1">3</span><span class="pl-kos">,</span><span class="pl-c1">1</span><span class="pl-kos">,</span><span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">)</span><span class="pl-kos">}</span></span>) * -1}).from(items)// and more!
🎉 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_systablesexport default defaultConfig({
dialect: "postgresql",
extensionsFilters: ["postgis"],
})
Improvements
Update zod schemas for database credentials and write tests to all the positive/negative cases
export default defaultConfig({
dialect: "postgresql",
dbCredentials: {
ssl: true, //"require" | "allow" | "prefer" | "verify-full" | options from node:tls
}
})
export default defaultConfig({
dialect: "mysql",
dbCredentials: {
ssl: "", // string | SslOptions (ssl options from mysql2 package)
}
})
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
CREATE UNIQUE INDEX
<span class="pl-en">emailUniqueIndex</span>ON</span>users<span class="pl-pds">(</span>lower("users"."email")<span class="pl-pds">);-- now
CREATE UNIQUE INDEX
<span class="pl-en">emailUniqueIndex</span>ON</span>users<span class="pl-pds">(lower("email"));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
index('my_name').on(table.id, table.email) // will work well
// but
index().on(sql
lower(<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">table</span><span class="pl-kos">.</span><span class="pl-c1">email</span><span class="pl-kos">}</span></span>)) // errorindex('my_name').on(sql
lower(<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">table</span><span class="pl-kos">.</span><span class="pl-c1">email</span><span class="pl-kos">}</span></span>)) // will work wellPush 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.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 DataAPIImportant
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.
For more information: