-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
300 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
dist | ||
coverage | ||
*.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import * as TypedPg from '../index' | ||
|
||
describe('TypedPg', () => { | ||
it('should be defined', () => { | ||
expect(Object.keys(TypedPg)).toEqual([ | ||
'Client', | ||
'createClient', | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest' | ||
import { type Client, createClient } from '../../client' | ||
import { QueryBuilder } from '../../query-builder' | ||
import { createTestingPostgres } from '../utils' | ||
|
||
describe('QueryBuilder/mutation', () => { | ||
let client: Client | ||
|
||
beforeAll(async () => { | ||
client = createClient(createTestingPostgres()) | ||
|
||
await client.raw` | ||
CREATE TABLE mutation ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT, | ||
metadata JSONB | ||
); | ||
` | ||
}) | ||
|
||
afterAll(async () => { | ||
await client.raw`DROP TABLE mutation` | ||
|
||
await client.quit() | ||
}) | ||
|
||
beforeEach(async () => { | ||
await client.raw`TRUNCATE mutation` | ||
|
||
await client.raw` | ||
INSERT INTO mutation (id, name, metadata) VALUES (1, 'Alice', '{"age":100}'), (2, 'Bob', '{}'); | ||
` | ||
}) | ||
|
||
describe('insert', () => { | ||
it('inserts a row', async () => { | ||
const returning = await new QueryBuilder(client, 'mutation').insert( | ||
{ | ||
id: 3, | ||
name: 'Charlie', | ||
metadata: { age: 50 }, | ||
}, | ||
{ returning: ['name', 'metadata'] } | ||
) | ||
|
||
expect(returning).toEqual([{ name: 'Charlie', metadata: { age: 50 } }]) | ||
|
||
const result = await new QueryBuilder(client, 'mutation').pluck('name') | ||
|
||
expect(result).toEqual(['Alice', 'Bob', 'Charlie']) | ||
}) | ||
}) | ||
|
||
describe('update', () => { | ||
it('updates a row', async () => { | ||
const returning = await new QueryBuilder(client, 'mutation') | ||
.where('name', 'Alice') | ||
.update({ name: 'David' }, { returning: ['name'] }) | ||
|
||
expect(returning).toEqual([{ name: 'David' }]) | ||
|
||
const result = await new QueryBuilder(client, 'mutation').pluck('name') | ||
|
||
expect(result).toEqual(['Bob', 'David']) | ||
}) | ||
}) | ||
|
||
describe('delete', () => { | ||
it('deletes a row', async () => { | ||
await new QueryBuilder(client, 'mutation') | ||
.where('name', 'Alice') | ||
.delete() | ||
|
||
const result = await new QueryBuilder(client, 'mutation').pluck('name') | ||
|
||
expect(result).toEqual(['Bob']) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.