Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
drizzle-orm-es
Advanced tools
Readme
Drizzle ORM is a TypeScript ORM for SQL databases designed with maximum type safety in mind. It comes with a drizzle-kit CLI companion for automatic SQL migrations generation. Drizzle ORM is meant to be a library, not a framework. It stays as an opt-in solution all the time at any levels.
The ORM main philosophy is "If you know SQL, you know Drizzle ORM". We follow the SQL-like syntax whenever possible, are strongly typed ground top and fail at compile time, not in runtime.
Drizzle ORM is being battle-tested on production projects by multiple teams 🚀 Give it a try and let us know if you have any questions or feedback on Discord.
Database | Status | |
---|---|---|
PostgreSQL | ✅ | Docs |
MySQL | ✅ | Docs |
SQLite | ✅ | Docs |
Cloudflare D1 | ✅ | Docs |
DynamoDB | ⏳ | |
MS SQL | ⏳ | |
CockroachDB | ⏳ |
npm install drizzle-orm
npm install -D drizzle-kit
Note: don't forget to install
pg
and@types/pg
packages for this example to work.
import { eq } from 'drizzle-orm/expressions';
import { drizzle } from 'drizzle-orm/node-postgres';
import { InferModel, integer, pgTable, serial, text, timestamp, varchar } from 'drizzle-orm/pg-core';
import { sql } from 'drizzle-orm/sql';
import { Pool } from 'pg';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
fullName: text('full_name').notNull(),
phone: varchar('phone', { length: 20 }).notNull(),
role: text<'user' | 'admin'>('role').default('user').notNull(),
cityId: integer('city_id').references(() => cities.id),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export type User = InferModel<typeof users>;
export type NewUser = InferModel<typeof users, 'insert'>;
export const cities = pgTable('cities', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
});
export type City = InferModel<typeof cities>;
export type NewCity = InferModel<typeof cities, 'insert'>;
const pool = new Pool({
connectionString: 'postgres://user:password@host:port/db',
});
const db = drizzle(pool);
// Insert
const newUser: NewUser = {
fullName: 'John Doe',
phone: '+123456789',
};
const insertedUsers /* : User[] */ = await db.insert(users).values(newUser).returning();
const insertedUser = insertedUsers[0]!;
const newCity: NewCity = {
name: 'New York',
};
const insertedCities /* : City[] */ = await db.insert(cities).values(newCity).returning();
const insertedCity = insertedCities[0]!;
// Update
const updateResult /* : { updated: Date }[] */ = await db.update(users)
.set({ cityId: insertedCity.id, updatedAt: new Date() })
.where(eq(users.id, insertedUser.id))
.returning({ updated: users.updatedAt });
// Select
const allUsers /* : User[] */ = await db.select().from(users);
// Select custom fields
const upperCaseNames /* : { id: number; name: string }[] */ = await db
.select({
id: users.id,
name: sql<string>`upper(${users.fullName})`,
})
.from(users);
// Joins
// You wouldn't BELIEVE how SMART the result type is! 😱
const allUsersWithCities = await db
.select({
id: users.id,
name: users.fullName,
city: {
id: cities.id,
name: cities.name,
},
})
.from(users)
.leftJoin(cities, eq(users.cityId, cities.id));
// Delete
const deletedNames /* : { name: string }[] */ = await db.delete(users)
.where(eq(users.id, insertedUser.id))
.returning({ name: users.fullName });
See full docs for further reference:
FAQs
Drizzle ORM package for SQL databases
The npm package drizzle-orm-es receives a total of 21 weekly downloads. As such, drizzle-orm-es popularity was classified as not popular.
We found that drizzle-orm-es demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.