drizzle-orm-pg
Advanced tools
Comparing version 0.12.0-beta.29 to 0.12.0-beta.30
{ | ||
"name": "drizzle-orm-pg", | ||
"version": "0.12.0-beta.29", | ||
"version": "0.12.0-beta.30", | ||
"description": "Drizzle ORM package for PostgreSQL database", | ||
@@ -39,2 +39,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@types/node": "*", | ||
"@types/pg": "^8.6.1", | ||
@@ -49,2 +50,3 @@ "concurrently": "^7.3.0", | ||
"type-fest": "^2.16.0", | ||
"typescript": "^4.8.4", | ||
"uvu": "^0.5.3" | ||
@@ -51,0 +53,0 @@ }, |
109
README.md
@@ -36,3 +36,2 @@ ## DrizzleORM [PostgreSQL] | ||
```typescript | ||
import { connect } from "drizzle-orm"; | ||
import { PgConnector, pgTable, serial, text, varchar } from "drizzle-orm-pg"; | ||
@@ -48,6 +47,6 @@ import { Pool } from "pg"; | ||
const pool = new Pool({ connectionString: "postgres://user:password@host:port/db" }); | ||
const connector = new PgConnector(pool, { users }); | ||
const db = await connect(connector); | ||
const connector = new PgConnector(pool); | ||
const db = await connector.connect(); | ||
const users = await db.users.select().execute(); | ||
const users = await db.select(users); | ||
``` | ||
@@ -57,3 +56,2 @@ | ||
```typescript | ||
import { connect } from "drizzle-orm"; | ||
import { PgConnector } from "drizzle-orm-pg"; | ||
@@ -71,4 +69,4 @@ import { Pool } from "pg"; | ||
const connector = new PgConnector(pool, { ...tables }); | ||
const db = await connect(connector); | ||
const connector = new PgConnector(pool); | ||
const db = await connector.connect(); | ||
``` | ||
@@ -189,3 +187,2 @@ | ||
... | ||
import { connect } from "drizzle-orm"; | ||
import { PgConnector, pgTable, serial, text, varchar } from "drizzle-orm-pg"; | ||
@@ -199,34 +196,28 @@ import { and, asc, desc, eq, or } from "drizzle-orm/expressions"; | ||
const connector = new PgConnector(..., { users }); | ||
const db = await connect(connector); | ||
const connector = new PgConnector(...); | ||
const db = await connector.connect(); | ||
await db.users.select().execute(); | ||
await db.users.select().where(eq(users.id, 42)).execute(); | ||
await db.select(users); | ||
await db.select(users).where(eq(users.id, 42)); | ||
// you can combine filters with eq(...) or or(...) | ||
await db.users | ||
.select() | ||
.where(and(eq(users.id, 42), eq(users.name, "Dan"))) | ||
.execute(); | ||
await db.select(users) | ||
.where(and(eq(users.id, 42), eq(users.name, "Dan"))); | ||
await db.users | ||
.select() | ||
.where(or(eq(users.id, 42), eq(users.id, 1))) | ||
.execute(); | ||
await db.select(users) | ||
.where(or(eq(users.id, 42), eq(users.id, 1))); | ||
// partial select | ||
const result = await db.users | ||
.select({ | ||
const result = await db.select(users).fields({ | ||
mapped1: users.id, | ||
mapped2: users.name, | ||
}) | ||
.execute(); | ||
}); | ||
const { mapped1, mapped2 } = result[0]; | ||
// limit offset & order by | ||
await db.users.select().limit(10).offset(10).execute() | ||
await db.users.select().orderBy(asc(users.name)).execute(); | ||
await db.users.select().orderBy(desc(users.name)).execute(); | ||
await db.select(users).limit(10).offset(10); | ||
await db.select(users).orderBy(asc(users.name)); | ||
await db.select(users).orderBy(desc(users.name)); | ||
// you can pass multiple order args | ||
await db.users.select().orderBy(asc(users.name), desc(users.name)).execute(); | ||
await db.select(users).orderBy(asc(users.name), desc(users.name)); | ||
@@ -279,3 +270,2 @@ // list of all filter operators | ||
```typescript | ||
import { connect } from "drizzle-orm"; | ||
import { PgConnector, pgTable, serial, text, timestamp } from "drizzle-orm-pg"; | ||
@@ -289,11 +279,14 @@ | ||
const connector = new PgConnector(..., { users }); | ||
const db = await connect(connector); | ||
const connector = new PgConnector(...); | ||
const db = await connector.connect(); | ||
await db.users.insert({ | ||
await db.insert(users | ||
.values({ | ||
name: "Andrew", | ||
createdAt: new Date(), | ||
}).execute(); | ||
}); | ||
await db.users.insert([ | ||
// accepts vararg of items | ||
await db.insert(users) | ||
.values( | ||
{ | ||
@@ -307,3 +300,15 @@ name: "Andrew", | ||
}, | ||
]).execute(); | ||
)); | ||
await db.insert(users) | ||
.values(...[ | ||
{ | ||
name: "Andrew", | ||
createdAt: new Date(), | ||
}, | ||
{ | ||
name: "Dan", | ||
createdAt: new Date(), | ||
}, | ||
]); | ||
``` | ||
@@ -313,10 +318,8 @@ | ||
```typescript | ||
await db.users.update() | ||
.where(eq(usersTable.name, 'Dan')) | ||
await db.update(users) | ||
.set({ name: 'Mr. Dan' }) | ||
.execute(); | ||
.where(eq(usersTable.name, 'Dan')); | ||
await db.users.delete() | ||
.where(eq(usersTable.name, 'Dan')) | ||
.execute(); | ||
await db.delete(users) | ||
.where(eq(usersTable.name, 'Dan')); | ||
``` | ||
@@ -328,3 +331,2 @@ | ||
```typescript | ||
import { connect } from "drizzle-orm"; | ||
import { PgConnector, pgTable, serial, text, timestamp } from "drizzle-orm-pg"; | ||
@@ -343,6 +345,6 @@ | ||
const connector = new PgConnector(..., { users, cities }); | ||
const db = await connect(connector); | ||
const connector = new PgConnector(...); | ||
const db = await connector.connect(); | ||
const result = db.cities.select().leftJoin(users, eq(cities2.id, users2.cityId)).execute() | ||
const result = db.select(cities).leftJoin(users, eq(cities2.id, users2.cityId)) | ||
``` | ||
@@ -368,11 +370,9 @@ | ||
... | ||
const connector = new PgConnector(..., { users, chatGroups, usersToChatGroups }); | ||
const db = await connect(connector); | ||
const connector = new PgConnector(...); | ||
const db = await connector.connect(); | ||
// querying user group with id 1 and all the participants(users) | ||
db.usersToChatGroups | ||
.select() | ||
.leftJoin(users, eq(usersToChatGroups.userId, users.id)) | ||
.leftJoin(chatGroups, eq(usersToChatGroups.groupId, chatGroups.id)) | ||
.execute(); | ||
db.select(usersToChatGroups) | ||
.leftJoin(users, eq(usersToChatGroups.userId, users.id)) | ||
.leftJoin(chatGroups, eq(usersToChatGroups.groupId, chatGroups.id)); | ||
``` | ||
@@ -383,7 +383,6 @@ | ||
```typescript | ||
await db.cities.select({ | ||
await db.select(cities).fields({ | ||
id: cities.id, | ||
cityName: cities.name | ||
}).leftJoin(users, eq(users.cityId, cities.id)) | ||
.execute(); | ||
}).leftJoin(users, eq(users.cityId, cities.id)); | ||
``` | ||
@@ -390,0 +389,0 @@ |
import { TableName } from 'drizzle-orm/branded-types'; | ||
import { PreparedQuery, SQL } from 'drizzle-orm/sql'; | ||
import { PgColumnDriverParam } from '../branded-types'; | ||
import { PgColumnDriverParam } from '~/branded-types'; | ||
export declare type PgSQL<TTableName extends TableName> = SQL<TTableName>; | ||
@@ -5,0 +5,0 @@ export declare type AnyPgSQL<TTableName extends TableName = TableName> = PgSQL<TTableName>; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
224673
144
3147
12
428
2