Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snyk] Upgrade drizzle-orm from 0.29.5 to 0.30.0 #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

catarizea
Copy link
Owner

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.29.5 to 0.30.0.

As this is a private repository, Snyk-bot does not have access. Therefore, this PR has been created automatically, but appears to have been created by a real user.

✨ Snyk has automatically assigned this pull request, set who gets assigned.

ℹ️ 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 2 versions ahead of your current version.
  • The recommended version was released 21 days ago, on 2024-03-07.
Release notes
Package name: drizzle-orm
  • 0.30.0 - 2024-03-07

    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 selected mode. 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, all postgres.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.

    https://github.com/Any way to change the types parsing after the client is created? porsager/postgres#761
    for (const type of ['1184', '1082', '1083', '1114']) {
    client.options.parsers[type as any] = transparentParser;
    client.options.serializers[type as any] = transparentParser;
    }">
    const transparentParser = (val: any) => val;

    // Override postgres.js default date parsers: Any way to change the types parsing after the client is created? porsager/postgres#761
    for (const type of ['1184', '1082', '1083', '1114']) {
    client.options.parsers[type as any] = transparentParser;
    client.options.serializers[type as any] = transparentParser;
    }

    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!

    • [BUG]: timestamp with mode string is returned as Date object instead of string - #806
    • [BUG]: Dates are always dates #971
    • [BUG]: Inconsistencies when working with timestamps and corresponding datetime objects in javascript. #1176
    • [BUG]: timestamp columns showing string type, however actually returning a Date object. #1185
    • [BUG]: Wrong data type for postgres date colum #1407
    • [BUG]: invalid timestamp conversion when using PostgreSQL with TimeZone set to UTC #1587
    • [BUG]: Postgres insert into timestamp with time zone removes milliseconds #1061
    • [BUG]: update timestamp field (using AWS Data API) #1164
    • [BUG]: Invalid date from relational queries #895
  • 0.30.0-373aad0 - 2024-03-08
  • 0.29.5 - 2024-03-06

    New Features

    🎉 WITH UPDATE, WITH DELETE, WITH INSERT - thanks @ L-Mario564

    You can now use WITH statements with INSERT, UPDATE and DELETE statements

    Usage examples

    const averageAmount = db.$with('average_amount').as(
    	db.select({ value: sql`avg(${orders.amount})`.as('value') }).from(orders),
    );
    const result = await db
    	.with(averageAmount)
    	.delete(orders)
    	.where(gt(orders.amount, sql`(select * from ${averageAmount})`))
    	.returning({
    		id: orders.id,
    	});

    Generated SQL:

    with "average_amount" as (select avg("amount") as "value" from "orders") 
    delete from "orders" 
    where "orders"."amount" > (select * from "average_amount") 
    returning "id"

    For more examples for all statements, check docs:

    🎉 Possibility to specify custom schema and custom name for migrations table - thanks @ g3r4n

    • Custom table for migrations

    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 option

    Usage example

    await migrate(db, {
    	migrationsFolder: './drizzle',
    	migrationsTable: 'my_migrations',
    });
    • Custom schema for migrations

    Works only with PostgreSQL databases

    To add a custom schema name for migrations stored inside your database, you should use the migrationsSchema option

    Usage example

    await migrate(db, {
    	migrationsFolder: './drizzle',
    	migrationsSchema: 'custom',
    });

    🎉 SQLite Proxy bacth and Relational Queries support

    • You can now use .query.findFirst and .query.findMany syntax with sqlite proxy driver

    • SQLite 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:

    http://localhost:3000/batch',
    { queries },
    );

    		return result;
    	} catch (e: any) {
    		console.error('Error from sqlite proxy server:', e);
    		throw e;
    	}
    },
    

    );">

    import { drizzle } from 'drizzle-orm/sqlite-proxy';

    type ResponseType = { rows: any[][] | any[] }[];

    const db = drizzle(
    async (sql, params, method) => {
    // single query logic
    },
    // new batch callback
    async (
    queries: {
    sql: string;
    params: any[];
    method: 'all' | 'run' | 'get' | 'values';
    }[],
    ) => {
    try {
    const result: ResponseType = await axios.post(
    'http://localhost:3000/batch',
    { queries },
    );

    		<span class="pl-k">return</span> <span class="pl-s1">result</span><span class="pl-kos">;</span>
    	<span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">e</span>: <span class="pl-smi">any</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    		<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">error</span><span class="pl-kos">(</span><span class="pl-s">'Error from sqlite proxy server:'</span><span class="pl-kos">,</span> <span class="pl-s1">e</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    		<span class="pl-k">throw</span> <span class="pl-s1">e</span><span class="pl-kos">;</span>
    	<span class="pl-kos">}</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    

    );

    And then you can use db.batch([]) method, that will proxy all queries

    Response from the batch should be an array of raw values (an array within an array), in the same order as they were sent to the proxy server

from drizzle-orm GitHub release notes

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:

🧐 View latest project report

👩‍💻 Set who automatically gets assigned

🛠 Adjust upgrade PR settings

🔕 Ignore this dependency or unsubscribe from future upgrade PRs

@catarizea catarizea self-assigned this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants