[Snyk] Upgrade drizzle-orm from 0.30.10 to 0.31.0 #35
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-top-banner](https://github.com/andygongea/OWASP-Benchmark/assets/818805/c518c423-16fe-447e-b67f-ad5a49b5d123)
Snyk has created this PR to upgrade drizzle-orm from 0.30.10 to 0.31.0.
ℹ️ 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 8 versions ahead of your current version.
The recommended version was released on 22 days ago.
Release notes
Package name: drizzle-orm
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
.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_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
// 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_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// 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
,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:
drizzle-kit@0.22.0
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
tablesexport 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
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
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
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
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
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.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 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: