-
Notifications
You must be signed in to change notification settings - Fork 180
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
1 parent
a5b2f36
commit 05e3c06
Showing
5 changed files
with
199 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterSequence } from '../../../src/operations/sequences'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('sequences', () => { | ||
describe('alterSequence', () => { | ||
const alterSequenceFn = alterSequence(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterSequenceFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-11: This should throw an error | ||
it('should return sql statement', () => { | ||
const statement = alterSequenceFn('serial', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual(`ALTER SEQUENCE "serial" | ||
;`); | ||
}); | ||
|
||
it('should return sql statement with sequenceOptions', () => { | ||
const statement = alterSequenceFn('serial', { | ||
restart: 105, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual(`ALTER SEQUENCE "serial" | ||
RESTART WITH 105;`); | ||
}); | ||
}); | ||
}); | ||
}); |
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,76 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createSequence } from '../../../src/operations/sequences'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('sequences', () => { | ||
describe('createSequence', () => { | ||
const createSequenceFn = createSequence(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createSequenceFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createSequenceFn('serial'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual(`CREATE SEQUENCE "serial" | ||
;`); | ||
}); | ||
|
||
it('should return sql statement with sequenceOptions', () => { | ||
const statement = createSequenceFn('serial', { | ||
temporary: true, | ||
ifNotExists: true, | ||
type: 'bigint', | ||
increment: 2, | ||
minvalue: 0, | ||
maxvalue: 1000, | ||
start: 1, | ||
cache: 1, | ||
cycle: true, | ||
owner: 'mytable.mycol', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
`CREATE TEMPORARY SEQUENCE IF NOT EXISTS "serial" | ||
AS bigint | ||
INCREMENT BY 2 | ||
MAXVALUE 1000 | ||
START WITH 1 | ||
CACHE 1 | ||
CYCLE | ||
OWNED BY mytable.mycol;` | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = createSequenceFn({ | ||
name: 'serial', | ||
schema: 'myschema', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
`CREATE SEQUENCE "myschema"."serial" | ||
;` | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createSequenceFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createSequenceFn.reverse('serial'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP SEQUENCE "serial";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,34 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropSequence } from '../../../src/operations/sequences'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('sequences', () => { | ||
describe('dropSequence', () => { | ||
const dropSequenceFn = dropSequence(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropSequenceFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropSequenceFn('serial'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('DROP SEQUENCE "serial";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropSequenceFn('serial', { | ||
ifExists: true, | ||
cascade: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'DROP SEQUENCE IF EXISTS "serial" CASCADE;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,51 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameSequence } from '../../../src/operations/sequences'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('sequences', () => { | ||
describe('renameSequence', () => { | ||
const renameSequenceFn = renameSequence(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameSequenceFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameSequenceFn('serial', 'serial2'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER SEQUENCE "serial" RENAME TO "serial2";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameSequenceFn( | ||
{ name: 'serial', schema: 'myschema' }, | ||
{ name: 'serial2', schema: 'myschema' } | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER SEQUENCE "myschema"."serial" RENAME TO "myschema"."serial2";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameSequenceFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameSequenceFn.reverse('serial', 'serial2'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER SEQUENCE "serial2" RENAME TO "serial";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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