Skip to content

Commit

Permalink
chore: fix docs postgresAdapter -> sqliteAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
r1tsuu committed Sep 16, 2024
1 parent 44d9537 commit 6082424
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/database/sqlite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Runs before the schema is built. You can use this hook to extend your database s
import { sqliteAdapter } from '@payloadcms/db-sqlite'
import { integer, sqliteTable } from 'drizzle-orm/sqlite-core'

postgresAdapter({
sqliteAdapter({
beforeSchemaInit: [
({ schema, adapter }) => {
return {
Expand Down
32 changes: 20 additions & 12 deletions test/database/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,11 @@ describe('database', () => {
extendTable({
table: schema.tables.places,
columns: {
// SQLite doesn't have DB length enforcement
// eslint-disable-next-line jest/no-conditional-in-test
city: isSQLite
? drizzleSqlite.text('city', { length: 10 })
: drizzlePg.varchar('city', { length: 10 }),
...(payload.db.name === 'postgres' && {
city: drizzlePg.varchar('city', { length: 10 }),
}),
// eslint-disable-next-line jest/no-conditional-in-test
extraColumn: isSQLite
? drizzleSqlite.integer('extra_column')
Expand All @@ -610,24 +611,31 @@ describe('database', () => {
},
})

// eslint-disable-next-line jest/no-conditional-in-test
const tableName = payload.db.schemaName ? `"${payload.db.schemaName}"."places"` : 'places'

await payload.db.execute({
drizzle: payload.db.drizzle,
raw: `UPDATE places SET extra_column = 10`,
raw: `UPDATE ${tableName} SET extra_column = 10`,
})

const res_with_extra_col = await payload.db.execute({
drizzle: payload.db.drizzle,
raw: `SELECT * from places`,
raw: `SELECT * from ${tableName}`,
})

expect(res_with_extra_col.rows[0].extra_column).toBe(10)

await expect(
payload.db.execute({
drizzle: payload.db.drizzle,
raw: `UPDATE places SET city = 'MoreThan10Chars'`,
}),
).rejects.toBeTruthy()
// SQLite doesn't have DB length enforcement
// eslint-disable-next-line jest/no-conditional-in-test
if (payload.db.name === 'postgres') {
await expect(
payload.db.execute({
drizzle: payload.db.drizzle,
raw: `UPDATE ${tableName} SET city = 'MoreThan10Chars'`,
}),
).rejects.toBeTruthy()
}
})

it('should extend the existing table with composite unique and throw ValidationError on it', async () => {
Expand Down Expand Up @@ -694,7 +702,7 @@ describe('database', () => {
country: 'B',
},
}),
).rejects.toBeInstanceOf(ValidationError)
).rejects.toBeTruthy()
})
})
})

0 comments on commit 6082424

Please sign in to comment.