Skip to content

Commit 48c5197

Browse files
committed
Fix tabs in README
1 parent 457b6ed commit 48c5197

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

.markdownlint.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ first-line-h1: false
33
line-length: false
44
MD010:
55
spaces_per_tab: 2
6-
code_blocks: false

README.md

+31-31
Original file line numberDiff line numberDiff line change
@@ -55,79 +55,79 @@ import { sql } from 'drizzle-orm/sql';
5555
import { Pool } from 'pg';
5656

5757
export const users = pgTable('users', {
58-
id: serial('id').primaryKey(),
59-
fullName: text('full_name').notNull(),
60-
phone: varchar('phone', { length: 20 }).notNull(),
61-
role: text<'user' | 'admin'>('role').default('user').notNull(),
62-
cityId: integer('city_id').references(() => cities.id),
63-
createdAt: timestamp('created_at').defaultNow().notNull(),
64-
updatedAt: timestamp('updated_at').defaultNow().notNull(),
58+
id: serial('id').primaryKey(),
59+
fullName: text('full_name').notNull(),
60+
phone: varchar('phone', { length: 20 }).notNull(),
61+
role: text<'user' | 'admin'>('role').default('user').notNull(),
62+
cityId: integer('city_id').references(() => cities.id),
63+
createdAt: timestamp('created_at').defaultNow().notNull(),
64+
updatedAt: timestamp('updated_at').defaultNow().notNull(),
6565
});
6666

6767
export type User = InferModel<typeof users>;
6868
export type NewUser = InferModel<typeof users, 'insert'>;
6969

7070
export const cities = pgTable('cities', {
71-
id: serial('id').primaryKey(),
72-
name: text('name').notNull(),
71+
id: serial('id').primaryKey(),
72+
name: text('name').notNull(),
7373
});
7474

7575
export type City = InferModel<typeof cities>;
7676
export type NewCity = InferModel<typeof cities, 'insert'>;
7777

7878
const pool = new Pool({
79-
connectionString: 'postgres://user:password@host:port/db',
79+
connectionString: 'postgres://user:password@host:port/db',
8080
});
8181

8282
const db = drizzle(pool);
8383

8484
// Insert
8585
const newUser: NewUser = {
86-
fullName: 'John Doe',
87-
phone: '+123456789',
86+
fullName: 'John Doe',
87+
phone: '+123456789',
8888
};
8989
const insertedUsers /* : User */ = await db.insert(users).values(newUser).returning();
9090
const insertedUser = insertedUsers[0]!;
9191

9292
const newCity: NewCity = {
93-
name: 'New York',
93+
name: 'New York',
9494
};
9595
const insertedCities /* : City */ = await db.insert(cities).values(newCity).returning();
9696
const insertedCity = insertedCities[0]!;
9797

9898
// Update
9999
const updateResult /* : { updated: Date }[] */ = await db.update(users)
100-
.set({ cityId: insertedCity.id, updatedAt: new Date() })
101-
.where(eq(users.id, insertedUser.id))
102-
.returning({ updated: users.updatedAt });
100+
.set({ cityId: insertedCity.id, updatedAt: new Date() })
101+
.where(eq(users.id, insertedUser.id))
102+
.returning({ updated: users.updatedAt });
103103

104104
// Select
105105
const allUsers /* : User[] */ = await db.select(users);
106106

107107
// Select custom fields
108108
const upperCaseNames /* : { id: number; name: string }[] */ = await db.select(users)
109-
.fields({
110-
id: users.id,
111-
name: sql`upper(${users.fullName})`.as<string>(),
112-
});
109+
.fields({
110+
id: users.id,
111+
name: sql`upper(${users.fullName})`.as<string>(),
112+
});
113113

114114
// Joins
115115
// You wouldn't BELIEVE how SMART the result type is! 😱
116116
const allUsersWithCities = await db.select(users)
117-
.fields({
118-
user: {
119-
id: users.id,
120-
name: users.fullName,
121-
},
122-
cityId: cities.id,
123-
cityName: cities.name,
124-
})
125-
.leftJoin(cities, eq(users.cityId, cities.id));
117+
.fields({
118+
user: {
119+
id: users.id,
120+
name: users.fullName,
121+
},
122+
cityId: cities.id,
123+
cityName: cities.name,
124+
})
125+
.leftJoin(cities, eq(users.cityId, cities.id));
126126

127127
// Delete
128128
const deletedNames /* : { name: string }[] */ = await db.delete(users)
129-
.where(eq(users.id, insertedUser.id))
130-
.returning({ name: users.fullName });
129+
.where(eq(users.id, insertedUser.id))
130+
.returning({ name: users.fullName });
131131
```
132132

133133
See [PostgreSQL docs](./drizzle-orm/src/pg-core/README.md) for full API reference.

0 commit comments

Comments
 (0)