[Snyk] Upgrade drizzle-orm from 0.36.0 to 0.39.1 #1249
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.
Snyk has created this PR to upgrade drizzle-orm from 0.36.0 to 0.39.1.
ℹ️ 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 79 versions ahead of your current version.
The recommended version was released a month ago.
Release notes
Package name: drizzle-orm
aliasedTable()New features
Bun SQL driver support
You can now use the new Bun SQL driver released in Bun v1.2.0 with Drizzle
const db = drizzle(process.env.PG_DB_URL!);
const result = await db.select().from(...);
or you can use Bun SQL instance
import { SQL } from 'bun';
const client = new SQL(process.env.PG_DB_URL!);
const db = drizzle({ client });
const result = await db.select().from(...);
Current Limitations:
jsonandjsonbinserts and selects currently perform an additionalJSON.stringifyon the Bun SQL side. Once this is removed, they should work properly. You can always use custom types and redefine the mappers to and from the database.datetime,date, andtimestampwill not work properly when usingmode: stringin Drizzle. This is due to Bun's API limitations, which prevent custom parsers for queries. As a result, Drizzle cannot control the response sent from Bun SQL to Drizzle. Once this feature is added to Bun SQL, it should work as expected.arraytypes currently have issues in Bun SQL.WITH now supports INSERT, UPDATE, DELETE and raw sql template
withandinsertid: serial('id').primaryKey(),
name: text('name').notNull(),
});
const sq = db.$with('sq').as(
db.insert(users).values({ name: 'John' }).returning(),
);
const result = await db.with(sq).select().from(sq);
withandupdateid: serial('id').primaryKey(),
name: text('name').notNull(),
});
const sq = db.$with('sq').as(
db.update(users).set({ age: 25 }).where(eq(users.name, 'John')).returning(),
);
const result = await db.with(sq).select().from(sq);
withanddeleteid: serial('id').primaryKey(),
name: text('name').notNull(),
});
const sq = db.$with('sq').as(
db.delete(users).where(eq(users.name, 'John')).returning(),
);
const result = await db.with(sq).select().from(sq);
withandsqlid: serial('id').primaryKey(),
name: text('name').notNull(),
});
const sq = db.$with('sq', {
userId: users.id,
data: {
name: users.name,
},
}).as(sql
select * from <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">users</span><span class="pl-kos">}</span></span> where <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">users</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span> = 'John');const result = await db.with(sq).select().from(sq);
New tables in
/neonimportIn this release you can use
neon_identityschema andusers_synctable inside this schema by just importing it from/neonconst neonIdentitySchema = pgSchema('neon_identity');
/**
* Table schema of the
users_synctable used by Neon Identity.* This table automatically synchronizes and stores user data from external authentication providers.
*
* @ schema neon_identity
* @ table users_sync
*/
export const usersSync = neonIdentitySchema.table('users_sync', {
rawJson: jsonb('raw_json').notNull(),
id: text().primaryKey().notNull(),
name: text(),
email: text(),
createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }),
deletedAt: timestamp('deleted_at', { withTimezone: true, mode: 'string' }),
});
Utils and small improvements
getViewNameutil functionexport const user = pgTable("user", {
id: serial(),
name: text(),
email: text(),
});
export const userView = pgView("user_view").as((qb) => qb.select().from(user));
const viewName = getViewName(userView)
Bug fixed and GitHub issue closed
vector- thanks @ mitchwadairNew features
USE INDEX,FORCE INDEXandIGNORE INDEXfor MySQLIn MySQL, the statements USE INDEX, FORCE INDEX, and IGNORE INDEX are hints used in SQL queries to influence how the query optimizer selects indexes. These hints provide fine-grained control over index usage, helping optimize performance when the default behavior of the optimizer is not ideal.
Use Index
The
USE INDEXhint suggests to the optimizer which indexes to consider when processing the query. The optimizer is not forced to use these indexes but will prioritize them if they are suitable.id: int('id').primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
}, () => [usersTableNameIndex]);
const usersTableNameIndex = index('users_name_index').on(users.name);
await db.select()
.from(users, { useIndex: usersTableNameIndex })
.where(eq(users.name, 'David'));
Ignore Index
The
IGNORE INDEXhint tells the optimizer to avoid using specific indexes for the query. MySQL will consider all other indexes (if any) or perform a full table scan if necessary.id: int('id').primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
}, () => [usersTableNameIndex]);
const usersTableNameIndex = index('users_name_index').on(users.name);
await db.select()
.from(users, { ignoreIndex: usersTableNameIndex })
.where(eq(users.name, 'David'));
Force Index
The
FORCE INDEXhint forces the optimizer to use the specified index(es) for the query. If the specified index cannot be used, MySQL will not fall back to other indexes; it might resort to a full table scan instead.id: int('id').primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
}, () => [usersTableNameIndex]);
const usersTableNameIndex = index('users_name_index').on(users.name);
await db.select()
.from(users, { forceIndex: usersTableNameIndex })
.where(eq(users.name, 'David'));
You can also combine those hints and use multiple indexes in a query if you need
Important
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: