github drizzle-team/drizzle-orm 0.23.0

latest releases: 0.30.10, 0.30.9, 0.30.8...
13 months ago
  • 🎉 Added Knex and Kysely adapters! They allow you to manage the schemas and migrations with Drizzle and query the data with your favorite query builder. See documentation for more details:

  • 🎉 Added "type maps" to all entities. You can access them via the special _ property. For example:

    const users = mysqlTable('users', {
      id: int('id').primaryKey(),
      name: text('name').notNull(),
    });
    
    type UserFields = typeof users['_']['columns'];
    type InsertUser = typeof users['_']['model']['insert'];

    Full documentation on the type maps is coming soon.

  • 🎉 Added .$type() method to all column builders to allow overriding the data type. It also replaces the optional generics on columns.

    // Before
    const test = mysqlTable('test', {
      jsonField: json<Data>('json_field'),
    });
    
    // After
    const test = mysqlTable('test', {
      jsonField: json('json_field').$type<Data>(),
    });
  • ❗ Changed syntax for text-based enum columns:

    // Before
    const test = mysqlTable('test', {
      role: text<'admin' | 'user'>('role'),
    });
    
    // After
    const test = mysqlTable('test', {
      role: text('role', { enum: ['admin', 'user'] }),
    });
  • 🎉 Allowed passing an array of values into .insert().values() directly without spreading:

    const users = mysqlTable('users', {
      id: int('id').primaryKey(),
      name: text('name').notNull(),
    });
    
    await users.insert().values([
      { name: 'John' },
      { name: 'Jane' },
    ]);

    The spread syntax is now deprecated and will be removed in one of the next releases.

  • 🎉 Added "table creators" to allow for table name customization:

    import { mysqlTableCreator } from 'drizzle-orm/mysql-core';
    
    const mysqlTable = mysqlTableCreator((name) => `myprefix_${name}`);
    
    const users = mysqlTable('users', {
      id: int('id').primaryKey(),
      name: text('name').notNull(),
    });
    
    // Users table is a normal table, but its name is `myprefix_users` in runtime
  • 🎉 Implemented support for selecting/joining raw SQL expressions:

    // select current_date + s.a as dates from generate_series(0,14,7) as s(a);
    const result = await db
      .select({
        dates: sql`current_date + s.a`,
      })
      .from(sql`generate_series(0,14,7) as s(a)`);
  • 🐛 Fixed a lot of bugs from user feedback on GitHub and Discord (thank you! ❤). Fixes #293 #301 #276 #269 #253 #311 #312

Don't miss a new drizzle-orm release

NewReleases is sending notifications on new releases.