Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

drizzle-orm-pg

Package Overview
Dependencies
Maintainers
3
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drizzle-orm-pg - npm Package Compare versions

Comparing version 0.15.4-335d188 to 0.16.0-11f7ff3

postgres.js/driver.d.ts

1

columns/index.d.ts

@@ -23,3 +23,2 @@ export * from './bigint';

export * from './varchar';
export * from './custom';
//# sourceMappingURL=index.d.ts.map

@@ -40,3 +40,2 @@ "use strict";

__exportStar(require("./varchar"), exports);
__exportStar(require("./custom"), exports);
//# sourceMappingURL=index.js.map

@@ -7,3 +7,3 @@ import { ColumnConfig } from 'drizzle-orm';

data: TData;
driverParam: string;
driverParam: TData | string;
}>> {

@@ -16,3 +16,3 @@ protected $pgColumnBuilderBrand: 'PgJsonBuilder';

data: TData;
driverParam: string;
driverParam: TData | string;
}>> {

@@ -25,4 +25,5 @@ protected $pgColumnBrand: 'PgJson';

mapToDriverValue(value: TData): string;
mapFromDriverValue(value: TData | string): TData;
}
export declare function json<TData = any>(name: string): PgJsonBuilder<TData>;
//# sourceMappingURL=json.d.ts.map

@@ -25,2 +25,13 @@ "use strict";

}
mapFromDriverValue(value) {
if (typeof value === 'string') {
try {
return JSON.parse(value);
}
catch (e) {
return value;
}
}
return value;
}
}

@@ -27,0 +38,0 @@ exports.PgJson = PgJson;

@@ -7,3 +7,3 @@ import { ColumnConfig } from 'drizzle-orm';

data: TData;
driverParam: string;
driverParam: TData | string;
}>> {

@@ -16,3 +16,3 @@ protected $pgColumnBuilderBrand: 'PgJsonbBuilder';

data: TData;
driverParam: string;
driverParam: TData | string;
}>> {

@@ -25,4 +25,5 @@ protected $pgColumnBrand: 'PgJsonb';

mapToDriverValue(value: TData): string;
mapFromDriverValue(value: TData | string): TData;
}
export declare function jsonb<TData = any>(name: string): PgJsonbBuilder<TData>;
//# sourceMappingURL=jsonb.d.ts.map

@@ -25,2 +25,13 @@ "use strict";

}
mapFromDriverValue(value) {
if (typeof value === 'string') {
try {
return JSON.parse(value);
}
catch (e) {
return value;
}
}
return value;
}
}

@@ -27,0 +38,0 @@ exports.PgJsonb = PgJsonb;

import { SQLWrapper } from 'drizzle-orm/sql';
import { QueryResult, QueryResultRow } from 'pg';
import { PgDialect } from './dialect';
import { PgDelete, PgInsertBuilder, PgSelect, PgUpdateBuilder } from './query-builders';
import { PgSession } from './session';
import { PgSession, QueryResultHKT, QueryResultKind } from './session';
import { AnyPgTable } from './table';
export declare class PgDatabase {
export declare class PgDatabase<TQueryResult extends QueryResultHKT, TSession extends PgSession> {
constructor(

@@ -12,9 +11,9 @@ /** @internal */

/** @internal */
session: PgSession);
session: TSession);
select<TTable extends AnyPgTable>(from: TTable): PgSelect<TTable>;
update<TTable extends AnyPgTable>(table: TTable): PgUpdateBuilder<TTable>;
insert<TTable extends AnyPgTable>(table: TTable): PgInsertBuilder<TTable>;
delete<TTable extends AnyPgTable>(table: TTable): PgDelete<TTable>;
execute<T extends QueryResultRow = QueryResultRow>(query: SQLWrapper): Promise<QueryResult<T>>;
update<TTable extends AnyPgTable>(table: TTable): PgUpdateBuilder<TTable, TQueryResult>;
insert<TTable extends AnyPgTable>(table: TTable): PgInsertBuilder<TTable, TQueryResult>;
delete<TTable extends AnyPgTable>(table: TTable): PgDelete<TTable, TQueryResult>;
execute<TRow extends Record<string, unknown> = Record<string, unknown>>(query: SQLWrapper): Promise<QueryResultKind<TQueryResult, TRow>>;
}
//# sourceMappingURL=db.d.ts.map
import { MigrationMeta } from 'drizzle-orm/migrator';
import { Query, SQL } from 'drizzle-orm/sql';
import { PgDatabase } from './db';
import { PgDeleteConfig, PgInsertConfig, PgUpdateConfig, PgUpdateSet } from './query-builders';

@@ -10,3 +9,2 @@ import { PgSelectConfig } from './query-builders/select.types';

migrate(migrations: MigrationMeta[], session: PgSession): Promise<void>;
createDB(session: PgSession): PgDatabase;
escapeName(name: string): string;

@@ -13,0 +11,0 @@ escapeParam(num: number): string;

@@ -23,3 +23,2 @@ "use strict";

const columns_1 = require("./columns");
const db_1 = require("./db");
const table_1 = require("./table");

@@ -67,5 +66,2 @@ class PgDialect {

}
createDB(session) {
return new db_1.PgDatabase(this, session);
}
escapeName(name) {

@@ -72,0 +68,0 @@ return `"${name}"`;

import { Logger } from 'drizzle-orm';
import { PgDatabase } from '../db';
import { PgDialect } from '../dialect';
import { NeonClient, NeonSession } from './session';
import { NeonClient, NeonQueryResultHKT, NeonSession } from './session';
export interface NeonDriverOptions {

@@ -19,4 +19,4 @@ logger?: Logger;

}
export { PgDatabase } from '../db';
export declare function drizzle(client: NeonClient, config?: DrizzleConfig): PgDatabase;
export declare type NeonDatabase = PgDatabase<NeonQueryResultHKT, NeonSession>;
export declare function drizzle(client: NeonClient, config?: DrizzleConfig): NeonDatabase;
//# sourceMappingURL=driver.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drizzle = exports.PgDatabase = exports.NeonDriver = void 0;
exports.drizzle = exports.NeonDriver = void 0;
const serverless_1 = require("@neondatabase/serverless");
const db_1 = require("../db");
const dialect_1 = require("../dialect");

@@ -24,4 +25,2 @@ const session_1 = require("./session");

exports.NeonDriver = NeonDriver;
var db_1 = require("../db");
Object.defineProperty(exports, "PgDatabase", { enumerable: true, get: function () { return db_1.PgDatabase; } });
function drizzle(client, config = {}) {

@@ -31,5 +30,5 @@ const dialect = new dialect_1.PgDialect();

const session = driver.createSession();
return dialect.createDB(session);
return new db_1.PgDatabase(dialect, session);
}
exports.drizzle = drizzle;
//# sourceMappingURL=driver.js.map
import { MigrationConfig } from 'drizzle-orm/migrator';
import { PgDatabase } from './driver';
export declare function migrate(db: PgDatabase, config: string | MigrationConfig): Promise<void>;
import { NeonDatabase } from './driver';
export declare function migrate(db: NeonDatabase, config: string | MigrationConfig): Promise<void>;
//# sourceMappingURL=migrator.d.ts.map

@@ -6,3 +6,4 @@ import { Client, Pool, PoolClient, QueryResult, QueryResultRow } from '@neondatabase/serverless';

import { SelectFieldsOrdered } from '../operations';
import { PgSession, PreparedQuery, PreparedQueryConfig } from '../session';
import { PgSession, PreparedQuery, PreparedQueryConfig, QueryResultHKT } from '../session';
import { Assume } from '../utils';
export declare type NeonClient = Pool | PoolClient | Client;

@@ -32,2 +33,5 @@ export declare class NeonPreparedQuery<T extends PreparedQueryConfig> extends PreparedQuery<T> {

}
export interface NeonQueryResultHKT extends QueryResultHKT {
type: QueryResult<Assume<this['row'], QueryResultRow>>;
}
//# sourceMappingURL=session.d.ts.map
import { Logger } from 'drizzle-orm';
import { PgDatabase } from '../db';
import { PgDialect } from '../dialect';
import { NodePgClient, NodePgSession } from './session';
import { NodePgClient, NodePgQueryResultHKT, NodePgSession } from './session';
export interface PgDriverOptions {

@@ -19,4 +19,4 @@ logger?: Logger;

}
export { PgDatabase } from '../db';
export declare function drizzle(client: NodePgClient, config?: DrizzleConfig): PgDatabase;
export declare type NodePgDatabase = PgDatabase<NodePgQueryResultHKT, NodePgSession>;
export declare function drizzle(client: NodePgClient, config?: DrizzleConfig): NodePgDatabase;
//# sourceMappingURL=driver.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drizzle = exports.PgDatabase = exports.NodePgDriver = void 0;
exports.drizzle = exports.NodePgDriver = void 0;
const pg_1 = require("pg");
const db_1 = require("../db");
const dialect_1 = require("../dialect");

@@ -24,4 +25,2 @@ const session_1 = require("./session");

exports.NodePgDriver = NodePgDriver;
var db_1 = require("../db");
Object.defineProperty(exports, "PgDatabase", { enumerable: true, get: function () { return db_1.PgDatabase; } });
function drizzle(client, config = {}) {

@@ -31,5 +30,5 @@ const dialect = new dialect_1.PgDialect();

const session = driver.createSession();
return dialect.createDB(session);
return new db_1.PgDatabase(dialect, session);
}
exports.drizzle = drizzle;
//# sourceMappingURL=driver.js.map
import { MigrationConfig } from 'drizzle-orm/migrator';
import { PgDatabase } from '../db';
export declare function migrate(db: PgDatabase, config: string | MigrationConfig): Promise<void>;
import { NodePgDatabase } from './driver';
export declare function migrate(db: NodePgDatabase, config: string | MigrationConfig): Promise<void>;
//# sourceMappingURL=migrator.d.ts.map

@@ -6,3 +6,4 @@ import { Logger } from 'drizzle-orm';

import { SelectFieldsOrdered } from '../operations';
import { PgSession, PreparedQuery, PreparedQueryConfig } from '../session';
import { PgSession, PreparedQuery, PreparedQueryConfig, QueryResultHKT } from '../session';
import { Assume } from '../utils';
export declare type NodePgClient = Pool | PoolClient | Client;

@@ -32,2 +33,5 @@ export declare class NodePgPreparedQuery<T extends PreparedQueryConfig> extends PreparedQuery<T> {

}
export interface NodePgQueryResultHKT extends QueryResultHKT {
type: QueryResult<Assume<this['row'], QueryResultRow>>;
}
//# sourceMappingURL=session.d.ts.map
{
"name": "drizzle-orm-pg",
"version": "0.15.4-335d188",
"version": "0.16.0-11f7ff3",
"description": "Drizzle ORM package for PostgreSQL database",

@@ -33,3 +33,5 @@ "scripts": {

"drizzle-orm": ">=0.15 <0.16",
"pg": ">=8 <9"
"pg": ">=8 <9",
"postgres": ">=3 <4",
"@neondatabase/serverless": ">=0.1 <0.2"
},

@@ -42,2 +44,8 @@ "peerDependenciesMeta": {

"optional": true
},
"postgres": {
"optional": true
},
"@neondatabase/serverless": {
"optional": true
}

@@ -49,4 +57,5 @@ },

"drizzle-orm": "link:../drizzle-orm/dist",
"pg": "^8.8.0"
"pg": "^8.8.0",
"postgres": "^3.3.3"
}
}
import { QueryPromise } from 'drizzle-orm/query-promise';
import { Query, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { QueryResult, QueryResultRow } from 'pg';
import { PgDialect } from '../dialect';
import { SelectFields, SelectFieldsOrdered, SelectResultFields } from '../operations';
import { PgSession, PreparedQuery, PreparedQueryConfig } from '../session';
import { PgSession, PreparedQuery, PreparedQueryConfig, QueryResultHKT, QueryResultKind } from '../session';
import { AnyPgTable, InferModel } from '../table';

@@ -13,5 +12,5 @@ export interface PgDeleteConfig {

}
export interface PgDelete<TTable extends AnyPgTable, TReturning extends QueryResultRow | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResult<never> : TReturning[]> {
export interface PgDelete<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> {
}
export declare class PgDelete<TTable extends AnyPgTable, TReturning extends QueryResultRow | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResult<never> : TReturning[]> implements SQLWrapper {
export declare class PgDelete<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
private session;

@@ -22,8 +21,8 @@ private dialect;

where(where: SQL | undefined): Omit<this, 'where'>;
returning(): Omit<PgDelete<TTable, InferModel<TTable>>, 'where' | 'returning'>;
returning<TSelectedFields extends SelectFields>(fields: TSelectedFields): Omit<PgDelete<TTable, SelectResultFields<TSelectedFields>>, 'where' | 'returning'>;
returning(): Omit<PgDelete<TTable, TQueryResult, InferModel<TTable>>, 'where' | 'returning'>;
returning<TSelectedFields extends SelectFields>(fields: TSelectedFields): Omit<PgDelete<TTable, TQueryResult, SelectResultFields<TSelectedFields>>, 'where' | 'returning'>;
toSQL(): Query;
private _prepare;
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
execute: TReturning extends undefined ? QueryResult<never> : TReturning[];
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
}>;

@@ -30,0 +29,0 @@ execute: ReturnType<this['prepare']>['execute'];

import { QueryPromise } from 'drizzle-orm/query-promise';
import { Param, Placeholder, Query, SQL, SQLWrapper } from 'drizzle-orm/sql';
import { QueryResult, QueryResultRow } from 'pg';
import { PgDialect } from '../dialect';
import { IndexColumn } from '../indexes';
import { SelectFields, SelectFieldsOrdered, SelectResultFields } from '../operations';
import { PgSession, PreparedQuery, PreparedQueryConfig } from '../session';
import { PgSession, PreparedQuery, PreparedQueryConfig, QueryResultHKT, QueryResultKind } from '../session';
import { AnyPgTable, InferModel } from '../table';

@@ -19,3 +18,3 @@ import { PgUpdateSetSource } from './update';

};
export declare class PgInsertBuilder<TTable extends AnyPgTable> {
export declare class PgInsertBuilder<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT> {
private table;

@@ -25,7 +24,7 @@ private session;

constructor(table: TTable, session: PgSession, dialect: PgDialect);
values(...values: PgInsertValue<TTable>[]): PgInsert<TTable>;
values(...values: PgInsertValue<TTable>[]): PgInsert<TTable, TQueryResult>;
}
export interface PgInsert<TTable extends AnyPgTable, TReturning extends QueryResultRow | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResult<never> : TReturning[]>, SQLWrapper {
export interface PgInsert<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]>, SQLWrapper {
}
export declare class PgInsert<TTable extends AnyPgTable, TReturning extends QueryResultRow | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResult<never> : TReturning[]> implements SQLWrapper {
export declare class PgInsert<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
private session;

@@ -37,4 +36,4 @@ private dialect;

constructor(table: TTable, values: PgInsertConfig['values'], session: PgSession, dialect: PgDialect);
returning(): Omit<PgInsert<TTable, InferModel<TTable>>, 'returning' | `onConflict${string}`>;
returning<TSelectedFields extends SelectFields>(fields: TSelectedFields): Omit<PgInsert<TTable, SelectResultFields<TSelectedFields>>, 'returning' | `onConflict${string}`>;
returning(): Omit<PgInsert<TTable, TQueryResult, InferModel<TTable>>, 'returning' | `onConflict${string}`>;
returning<TSelectedFields extends SelectFields>(fields: TSelectedFields): Omit<PgInsert<TTable, TQueryResult, SelectResultFields<TSelectedFields>>, 'returning' | `onConflict${string}`>;
onConflictDoNothing(config?: {

@@ -52,3 +51,3 @@ target?: IndexColumn | IndexColumn[];

prepare(name: string): PreparedQuery<PreparedQueryConfig & {
execute: TReturning extends undefined ? QueryResult<never> : TReturning[];
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
}>;

@@ -55,0 +54,0 @@ execute: ReturnType<this['prepare']>['execute'];

@@ -5,6 +5,5 @@ import { GetColumnData } from 'drizzle-orm';

import { Simplify } from 'drizzle-orm/utils';
import { QueryResult, QueryResultRow } from 'pg';
import { PgDialect } from '../dialect';
import { SelectFields, SelectFieldsOrdered, SelectResultFields } from '../operations';
import { PgSession, PreparedQuery, PreparedQueryConfig } from '../session';
import { PgSession, PreparedQuery, PreparedQueryConfig, QueryResultHKT, QueryResultKind } from '../session';
import { AnyPgTable, GetTableConfig, InferModel } from '../table';

@@ -21,3 +20,3 @@ export interface PgUpdateConfig {

export declare type PgUpdateSet = Record<string, SQL | Param | null | undefined>;
export declare class PgUpdateBuilder<TTable extends AnyPgTable> {
export declare class PgUpdateBuilder<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT> {
private table;

@@ -28,7 +27,7 @@ private session;

constructor(table: TTable, session: PgSession, dialect: PgDialect);
set(values: PgUpdateSetSource<TTable>): PgUpdate<TTable>;
set(values: PgUpdateSetSource<TTable>): PgUpdate<TTable, TQueryResult>;
}
export interface PgUpdate<TTable extends AnyPgTable, TReturning extends QueryResultRow | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResult<never> : TReturning[]>, SQLWrapper {
export interface PgUpdate<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]>, SQLWrapper {
}
export declare class PgUpdate<TTable extends AnyPgTable, TReturning extends QueryResultRow | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResult<never> : TReturning[]> implements SQLWrapper {
export declare class PgUpdate<TTable extends AnyPgTable, TQueryResult extends QueryResultHKT, TReturning extends Record<string, unknown> | undefined = undefined> extends QueryPromise<TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[]> implements SQLWrapper {
private session;

@@ -41,8 +40,8 @@ private dialect;

where(where: SQL | undefined): Omit<this, 'where'>;
returning(): Omit<PgUpdate<TTable, InferModel<TTable>>, 'where' | 'returning'>;
returning<TSelectedFields extends SelectFields>(fields: TSelectedFields): Omit<PgUpdate<TTable, SelectResultFields<TSelectedFields>>, 'where' | 'returning'>;
returning(): Omit<PgUpdate<TTable, TQueryResult, InferModel<TTable>>, 'where' | 'returning'>;
returning<TSelectedFields extends SelectFields>(fields: TSelectedFields): Omit<PgUpdate<TTable, TQueryResult, SelectResultFields<TSelectedFields>>, 'where' | 'returning'>;
toSQL(): Query;
private _prepare;
prepare(name: string): PreparedQuery<PreparedQueryConfig & {
execute: TReturning extends undefined ? QueryResult<never> : TReturning[];
execute: TReturning extends undefined ? QueryResultKind<TQueryResult, never> : TReturning[];
}>;

@@ -49,0 +48,0 @@ execute: ReturnType<this['prepare']>['execute'];

<div align='center'>
<h1>Drizzle ORM | PostgreSQL <a href=''><img alt='npm' src='https://img.shields.io/npm/v/drizzle-orm-pg?label='></a></h1>
<img alt='npm' src='https://img.shields.io/npm/dm/drizzle-orm-pg'>
<img alt='pg version' src='https://img.shields.io/npm/dependency-version/drizzle-orm-pg/peer/pg'>
<img alt='npm bundle size' src='https://img.shields.io/bundlephobia/min/drizzle-orm-pg'>

@@ -14,2 +13,8 @@ <a href='https://discord.gg/yfjTbVXMW4'><img alt='Discord' src='https://img.shields.io/discord/1043890932593987624'></a>

| Driver | Support | ๐Ÿ“– | Driver version |
| :- | :-: | :-: | :-: |
| [node-postgres](https://github.com/brianc/node-postgres) | โœ… | | <img alt='driver version' src='https://img.shields.io/npm/dependency-version/drizzle-orm-pg/peer/pg'> |
| [postgres.js](https://github.com/porsager/postgres) | โœ… | [Docs](./src/postgres.js/README.md) | <img alt='driver version' src='https://img.shields.io/npm/dependency-version/drizzle-orm-pg/peer/postgres'> |
| [NeonDB Serverless](https://github.com/neondatabase/serverless) | โœ… | | <img alt='driver version' src='https://img.shields.io/npm/dependency-version/drizzle-orm-pg/peer/@neondatabase/serverless'> |
## Installation

@@ -40,3 +45,3 @@

```
```plaintext
๐Ÿ“ฆ <project root>

@@ -50,3 +55,3 @@ โ”” ๐Ÿ“‚ src

```
```plaintext
๐Ÿ“ฆ <project root>

@@ -162,4 +167,4 @@ โ”” ๐Ÿ“‚ src

```typescript
import { PgDatabase, pgTable, InferModel, serial, text, varchar } from 'drizzle-orm-pg';
import { drizzle } from 'drizzle-orm-pg';
import { pgTable, InferModel, serial, text, varchar } from 'drizzle-orm-pg';
import { drizzle, NodePgDatabase } from 'drizzle-orm-pg/node';

@@ -179,3 +184,3 @@ const users = pgTable('users', {

export const db: PgDatabase = drizzle(pool);
export const db: NodePgDatabase = drizzle(pool);

@@ -198,7 +203,7 @@ const result: User[] = await db.select(users);

population: integer('population'),
}, (table) => {
}, (countries) => {
return {
nameIdx: index('name_idx').on(table.name), // one column
namePopulationIdx: index('name_population_idx').on(table.name, table.population), // multiple columns
uniqueIdx: uniqueIndex('unique_idx').on(table.name), // unique index
nameIdx: index('name_idx').on(countries.name), // one column
namePopulationIdx: index('name_population_idx').on(countries.name, countries.population), // multiple columns
uniqueIdx: uniqueIndex('unique_idx').on(countries.name), // unique index
}

@@ -242,2 +247,3 @@ })

## Column types
The list of all column types. You can also create custom types - [see here](https://github.com/drizzle-team/drizzle-orm/blob/main/docs/custom-types.md).

@@ -292,2 +298,3 @@

## Table schemas
Drizzle won't append any schema before table definition by default. So if your tables are in `public` schema drizzle generate -> `select * from "users"`

@@ -299,7 +306,7 @@

> If you will have tables with same names in different schemas then drizzle will respond with `never[]` error in result types and error from database
>
>
> In this case you may use [alias syntax](https://github.com/drizzle-team/drizzle-orm/tree/main/drizzle-orm-pg#join-aliases-and-self-joins)
### Usage example
#### Usage example
```typescript

@@ -320,7 +327,7 @@ // Table in default schema

const usersTable = mySchema('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: jsonb<string[]>('jsonb'),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
id: serial('id').primaryKey(),
name: text('name').notNull(),
verified: boolean('verified').notNull().default(false),
jsonb: jsonb<string[]>('jsonb'),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
});

@@ -475,20 +482,20 @@ ```

await db.insert(users)
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } });
.values({ id: 1, name: 'Dan' })
.onConflictDoUpdate({ target: users.id, set: { name: 'John' } });
await db.insert(users)
.values({ id: 1, name: 'John' })
.onConflictDoNothing();
.values({ id: 1, name: 'John' })
.onConflictDoNothing();
await db.insert(users)
.values({ id: 1, name: 'John' })
.onConflictDoNothing({ target: users.id });
.values({ id: 1, name: 'John' })
.onConflictDoNothing({ target: users.id });
await db.insert(users)
.values({ id: 1, name: 'John' })
.onConflictDoUpdate({
target: users.id,
set: { name: 'John1' },
where: sql`${users.createdAt} > '2023-01-01'::date`,
});
.values({ id: 1, name: 'John' })
.onConflictDoUpdate({
target: users.id,
set: { name: 'John1' },
where: sql`${users.createdAt} > '2023-01-01'::date`,
});
```

@@ -500,25 +507,25 @@

await db.update(users)
.set({ name: 'Mr. Dan' })
.where(eq(users.name, 'Dan'));
.set({ name: 'Mr. Dan' })
.where(eq(users.name, 'Dan'));
const updatedUser: InferModel<typeof users> = await db.delete(users)
.set({ name: 'Mr. Dan' })
.where(eq(users.name, 'Dan'))
.returning();
.set({ name: 'Mr. Dan' })
.where(eq(users.name, 'Dan'))
.returning();
const updatedUserId: { updatedId: number }[] = await db.update(users)
.set({ name: 'Mr. Dan' })
.where(eq(users.name, 'Dan'))
.returning({ updatedId: users.id });
.set({ name: 'Mr. Dan' })
.where(eq(users.name, 'Dan'))
.returning({ updatedId: users.id });
await db.delete(users)
.where(eq(users.name, 'Dan'));
.where(eq(users.name, 'Dan'));
const deletedUser: InferModel<typeof users> = await db.delete(users)
.where(eq(users.name, 'Dan'))
.returning();
.where(eq(users.name, 'Dan'))
.returning();
const deletedUserId: { deletedId: number }[] = await db.delete(users)
.where(eq(users.name, 'Dan'))
.returning({ deletedId: users.id });
.where(eq(users.name, 'Dan'))
.returning({ deletedId: users.id });
```

@@ -534,14 +541,14 @@

const cities = pgTable('cities', {
id: serial('id').primaryKey(),
name: text('name'),
id: serial('id').primaryKey(),
name: text('name'),
});
const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name'),
cityId: integer('city_id').references(() => cities.id),
id: serial('id').primaryKey(),
name: text('name'),
cityId: integer('city_id').references(() => cities.id),
});
const result = db.select(cities)
.leftJoin(users, eq(cities2.id, users2.cityId));
.leftJoin(users, eq(cities2.id, users2.cityId));
```

@@ -553,14 +560,14 @@

const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name'),
id: serial('id').primaryKey(),
name: text('name'),
});
const chatGroups = pgTable('chat_groups', {
id: serial('id').primaryKey(),
name: text('name'),
id: serial('id').primaryKey(),
name: text('name'),
});
const usersToChatGroups = pgTable('usersToChatGroups', {
userId: integer('user_id').notNull().references(() => users.id),
groupId: integer('group_id').notNull().references(() => chatGroups.id),
userId: integer('user_id').notNull().references(() => users.id),
groupId: integer('group_id').notNull().references(() => chatGroups.id),
});

@@ -570,5 +577,5 @@

const result = await db.select(usersToChatGroups)
.leftJoin(users, eq(usersToChatGroups.userId, users.id))
.leftJoin(chatGroups, eq(usersToChatGroups.groupId, chatGroups.id))
.where(eq(chatGroups.id, 1));
.leftJoin(users, eq(usersToChatGroups.userId, users.id))
.leftJoin(chatGroups, eq(usersToChatGroups.groupId, chatGroups.id))
.where(eq(chatGroups.id, 1));
```

@@ -599,5 +606,5 @@

const result1 = await db.select(cities).fields({
userId: users.id,
cityId: cities.id,
cityName: cities.name,
userId: users.id,
cityId: cities.id,
cityName: cities.name,
}).leftJoin(users, eq(users.cityId, cities.id));

@@ -607,8 +614,8 @@

const result2 = await db.select(cities).fields({
// Supports any level of nesting!
user: users,
city: {
id: cities.id,
name: cities.name,
},
// Supports any level of nesting!
user: users,
city: {
id: cities.id,
name: cities.name,
},
}).leftJoin(users, eq(users.cityId, cities.id));

@@ -621,4 +628,4 @@ ```

const query = db.select(users)
.where(eq(users.name, 'Dan'))
.prepare();
.where(eq(users.name, 'Dan'))
.prepare();

@@ -634,4 +641,4 @@ const result = await query.execute();

const query = db.select(users)
.where(eq(users.name, placeholder('name')))
.prepare();
.where(eq(users.name, placeholder('name')))
.prepare();

@@ -648,3 +655,3 @@ const result = await query.execute({ name: 'Dan' });

const res: QueryResult<{ id: number; name: string }> = await db.execute<
{ id: number; name: string }
{ id: number; name: string }
>(sql`select * from ${users} where ${users.id} = ${userId}`);

@@ -684,10 +691,10 @@ ```

CREATE TABLE IF NOT EXISTS auth_otp (
'id' SERIAL PRIMARY KEY,
'phone' character varying(256),
'user_id' INT
'id' SERIAL PRIMARY KEY,
'phone' character varying(256),
'user_id' INT
);
CREATE TABLE IF NOT EXISTS users (
'id' SERIAL PRIMARY KEY,
'full_name' character varying(256)
'id' SERIAL PRIMARY KEY,
'full_name' character varying(256)
);

@@ -712,3 +719,3 @@

const pool = new Pool({
connectionString: 'postgres://user:password@host:port/db',
connectionString: 'postgres://user:password@host:port/db',
});

@@ -715,0 +722,0 @@ const db = drizzle(pool);

@@ -20,2 +20,10 @@ import { Query, SQL } from 'drizzle-orm/sql';

}
export interface QueryResultHKT {
readonly $brand: 'QueryRowHKT';
readonly row: unknown;
readonly type: unknown;
}
export declare type QueryResultKind<TKind extends QueryResultHKT, TRow> = (TKind & {
readonly row: TRow;
})['type'];
//# sourceMappingURL=session.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc