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

docs: update #387

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/content/documentation/docs/indexes-constraints.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ To declare multicolumn foreign keys you can use a dedicated `foreignKey` operato

</Tab>
<Tab>
```typescript {4-5,14-15,18-21}
```typescript copy {4-5,14-15,18-21}
import { integer, text, primaryKey, foreignKey, sqliteTable, AnySQLiteColumn } from "drizzle-orm/sqlite-core";

export const user = sqliteTable("user", {
Expand Down
24 changes: 14 additions & 10 deletions src/content/documentation/docs/joins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ Drizzle ORM supports table aliases which comes really handy when you need to do
Lets say you need to fetch users with their parents:
<CodeTabs items={["index.ts", "schema.ts"]}>
<CodeTab>
```typescript copy
```typescript copy {5,9}
import { eq } from 'drizzle-orm';
import { alias } from 'drizzle-orm/pg-core';
import { user } from "./schema";

const parent = aliasedTable(user, "parent")
const result = db
const parent = alias(user, "parent")
const result = await db
.select()
.from(user)
.leftJoin(parent, eq(parent.id, user.parentId));
Expand All @@ -219,22 +221,24 @@ const result: {
user: {
id: number;
name: string;
parentId: number;
parentId: number | null;
};
parent: {
id: number;
name: string;
parentId: number;
parentId: number | null;
} | null;
}[];
```
</CodeTab>

```typescript
export const user = pgTable("user", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
parentId: integer("parent_id").notNull().references((): AnyPgColumn => user.id)
```typescript copy {6}
import { pgTable, integer, text, AnyPgColumn } from 'drizzle-orm/pg-core';

export const user = pgTable('user', {
id: integer('id').primaryKey(),
name: text('name').notNull(),
parentId: integer('parent_id').references((): AnyPgColumn => user.id),
});
```

Expand Down
60 changes: 31 additions & 29 deletions src/content/documentation/docs/operators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SELECT * FROM table WHERE table.column = 5


<Section>
```typescript
```typescript copy
import { eq } from "drizzle-orm";

db.select().from(table).where(eq(table.column1, table.column2));
Expand All @@ -45,7 +45,7 @@ SELECT * FROM table WHERE table.column1 = table.column2

Value is not equal to `n`
<Section>
```typescript
```typescript copy
import { ne } from "drizzle-orm";

db.select().from(table).where(ne(table.column, 5));
Expand All @@ -58,7 +58,7 @@ SELECT * FROM table WHERE table.column <> 5


<Section>
```typescript
```typescript copy
import { ne } from "drizzle-orm";

db.select().from(table).where(ne(table.column1, table.column2));
Expand All @@ -75,7 +75,7 @@ SELECT * FROM table WHERE table.column1 <> table.column2

Value is greater than `n`
<Section>
```typescript
```typescript copy
import { gt } from "drizzle-orm";

db.select().from(table).where(gt(table.column, 5));
Expand All @@ -88,7 +88,7 @@ SELECT * FROM table WHERE table.column > 5


<Section>
```typescript
```typescript copy
import { gt } from "drizzle-orm";

db.select().from(table).where(gt(table.column1, table.column2));
Expand All @@ -104,7 +104,7 @@ SELECT * FROM table WHERE table.column1 > table.column2

Value is greater than or equal to `n`
<Section>
```typescript
```typescript copy
import { gte } from "drizzle-orm";

db.select().from(table).where(gte(table.column, 5));
Expand All @@ -117,7 +117,7 @@ SELECT * FROM table WHERE table.column >= 5


<Section>
```typescript
```typescript copy
import { gte } from "drizzle-orm";

db.select().from(table).where(gte(table.column1, table.column2));
Expand All @@ -133,7 +133,7 @@ SELECT * FROM table WHERE table.column1 >= table.column2

Value is less than `n`
<Section>
```typescript
```typescript copy
import { lt } from "drizzle-orm";

db.select().from(table).where(lt(table.column, 5));
Expand All @@ -146,7 +146,7 @@ SELECT * FROM table WHERE table.column < 5


<Section>
```typescript
```typescript copy
import { lt } from "drizzle-orm";

db.select().from(table).where(lt(table.column1, table.column2));
Expand All @@ -163,7 +163,7 @@ SELECT * FROM table WHERE table.column1 < table.column2
Value is less than or equal to `n`.

<Section>
```typescript
```typescript copy
import { lte } from "drizzle-orm";

db.select().from(table).where(lte(table.column, 5));
Expand All @@ -175,7 +175,7 @@ SELECT * FROM table WHERE table.column <= 5
</Section>

<Section>
```typescript
```typescript copy
import { lte } from "drizzle-orm";

db.select().from(table).where(lte(table.column1, table.column2));
Expand All @@ -192,7 +192,7 @@ SELECT * FROM table WHERE table.column1 <= table.column2

Value is `null`
<Section>
```typescript
```typescript copy
import { isNull } from "drizzle-orm";

db.select().from(table).where(isNull(table.column));
Expand All @@ -209,7 +209,7 @@ SELECT * FROM table WHERE table.column IS NULL

Value is not `null`
<Section>
```typescript
```typescript copy
import { isNotNull } from "drizzle-orm";

db.select().from(table).where(isNotNull(table.column));
Expand All @@ -225,7 +225,7 @@ SELECT * FROM table WHERE table.column IS NOT NULL

Value is in array of values
<Section>
```typescript
```typescript copy
import { inArray } from "drizzle-orm";

db.select().from(table).where(inArray(table.column, [1, 2, 3, 4]));
Expand All @@ -237,7 +237,7 @@ SELECT * FROM table WHERE table.column in (1, 2, 3, 4)
</Section>

<Section>
```typescript
```typescript copy
import { inArray } from "drizzle-orm";

const query = db.select({ data: table2.column }).from(table2);
Expand All @@ -254,7 +254,7 @@ SELECT * FROM table WHERE table.column IN (SELECT table2.column FROM table2)

Value is not in array of values
<Section>
```typescript
```typescript copy
import { notInArray } from "drizzle-orm";

db.select().from(table).where(notInArray(table.column, [1, 2, 3, 4]));
Expand All @@ -266,7 +266,7 @@ SELECT * FROM table WHERE table.column NOT in (1, 2, 3, 4)
</Section>

<Section>
```typescript
```typescript copy
import { notInArray } from "drizzle-orm";

const query = db.select({ data: table2.column }).from(table2);
Expand All @@ -283,7 +283,7 @@ SELECT * FROM table WHERE table.column NOT IN (SELECT table2.column FROM table2)

Value exists
<Section>
```typescript
```typescript copy
import { exists } from "drizzle-orm";

const query = db.select().from(table2)
Expand All @@ -297,6 +297,8 @@ SELECT * FROM table WHERE EXISTS (SELECT * from table2)

### notExists

<IsSupportedChipGroup chips={{ 'PostgreSQL': true, 'MySQL': true, 'SQLite': true }} />

<Section>
```typescript
import { notExists } from "drizzle-orm";
Expand All @@ -315,7 +317,7 @@ SELECT * FROM table WHERE NOT EXISTS (SELECT * from table2)

Value is between two values
<Section>
```typescript
```typescript copy
import { between } from "drizzle-orm";

db.select().from(table).where(between(table.column, 2, 7));
Expand All @@ -331,7 +333,7 @@ SELECT * FROM table WHERE table.column BETWEEN 2 AND 7

Value is not between two value
<Section>
```typescript
```typescript copy
import { notBetween } from "drizzle-orm";

db.select().from(table).where(notBetween(table.column, 2, 7));
Expand All @@ -347,7 +349,7 @@ SELECT * FROM table WHERE table.column NOT BETWEEN 2 AND 7

Value is like other value, case sensitive
<Section>
```typescript
```typescript copy
import { like } from "drizzle-orm";

db.select().from(table).where(like(table.column, "%llo wor%"));
Expand All @@ -363,7 +365,7 @@ SELECT * FROM table WHERE table.column LIKE '%llo wor%'

Value is like some other value, case insensitive
<Section>
```typescript
```typescript copy
import { ilike } from "drizzle-orm";

db.select().from(table).where(ilike(table.column, "%llo wor%"));
Expand All @@ -379,7 +381,7 @@ SELECT * FROM table WHERE table.column ILIKE '%llo wor%'

Value is not like some other value, case insensitive
<Section>
```typescript
```typescript copy
import { notIlike } from "drizzle-orm";

db.select().from(table).where(notIlike(table.column, "%llo wor%"));
Expand All @@ -396,7 +398,7 @@ SELECT * FROM table WHERE table.column NOT ILIKE '%llo wor%'
All conditions must return `false`.

<Section>
```typescript
```typescript copy
import { eq, not } from "drizzle-orm";

db.select().from(table).where(not(eq(table.column, 5)));
Expand All @@ -413,7 +415,7 @@ SELECT * FROM table WHERE NOT (table.column = 5)
All conditions must return `true`.

<Section>
```typescript
```typescript copy
import { gt, lt, and } from "drizzle-orm";

db.select().from(table).where(and(gt(table.column, 5), lt(table.column, 7)));
Expand All @@ -430,7 +432,7 @@ SELECT * FROM table WHERE (table.column > 5 AND table.column < 7)
One or more conditions must return `true`.

<Section>
```typescript
```typescript copy
import { gt, lt, or } from "drizzle-orm";

db.select().from(table).where(or(gt(table.column, 5), lt(table.column, 7)));
Expand All @@ -447,7 +449,7 @@ SELECT * FROM table WHERE (table.column > 5 OR table.column < 7)
Test that a column or expression contains all elements of the list passed as the second argument

<Section>
```typescript
```typescript copy
import { arrayContains } from "drizzle-orm";

const contains = await db.select({ id: posts.id }).from(posts)
Expand All @@ -472,7 +474,7 @@ select "id" from "posts" where "posts"."tags" @> (select "tags" from "posts" whe
Test that the list passed as the second argument contains all elements of a column or expression

<Section>
```typescript
```typescript copy
import { arrayContained } from "drizzle-orm";

const contained = await db.select({ id: posts.id }).from(posts)
Expand All @@ -490,7 +492,7 @@ select "id" from "posts" where "posts"."tags" <@ {Typescript,ORM};
Test that a column or expression contains any elements of the list passed as the second argument.

<Section>
```typescript
```typescript copy
import { arrayOverlaps } from "drizzle-orm";

const overlaps = await db.select({ id: posts.id }).from(posts)
Expand Down
Loading