Skip to content

Commit

Permalink
operation-node-transformer fixed:
Browse files Browse the repository at this point in the history
- added copy of orderBy and limit properties in transformDeleteQuery
- added copy of ifNotExists property in transformCreateSchema
  • Loading branch information
Šuška Boris authored and koskimas committed Jul 3, 2022
1 parent a1d96b7 commit ceb59c3
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/operation-node/operation-node-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ export class OperationNodeTransformer {
where: this.transformNode(node.where),
returning: this.transformNode(node.returning),
with: this.transformNode(node.with),
orderBy: this.transformNode(node.orderBy),
limit: this.transformNode(node.limit),
}
}

Expand Down Expand Up @@ -619,6 +621,7 @@ export class OperationNodeTransformer {
return {
kind: 'CreateSchemaNode',
schema: this.transformNode(node.schema),
ifNotExists: node.ifNotExists,
}
}

Expand Down
102 changes: 102 additions & 0 deletions test/node/src/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,108 @@ for (const dialect of BUILT_IN_DIALECTS) {
})
})

describe('create schema', () => {
if (dialect === 'postgres' || dialect === 'mysql') {
beforeEach(cleanup)
afterEach(cleanup)

it('should create a schema', async () => {
const builder = ctx.db.schema
.createSchema('pets')

testSql(builder, dialect, {
postgres: {
sql: `create schema "pets"`,
parameters: [],
},
mysql: {
sql: "create schema `pets`",
parameters: [],
},
sqlite: NOT_SUPPORTED
})

await builder.execute()
})

it('should create a schema if not exists', async () => {
const builder = ctx.db.schema
.createSchema('pets')
.ifNotExists()

testSql(builder, dialect, {
postgres: {
sql: `create schema if not exists "pets"`,
parameters: [],
},
mysql: {
sql: "create schema if not exists `pets`",
parameters: [],
},
sqlite: NOT_SUPPORTED,
})

await builder.execute()
})
}

async function cleanup() {
await ctx.db.schema.dropSchema('pets').ifExists().execute()
}
})

describe('drop schema', () => {
if (dialect === 'postgres' || dialect === 'mysql') {
beforeEach(cleanup)
afterEach(cleanup)

it('should create a schema', async () => {
await ctx.db.schema.createSchema('pets').execute();

const builder = ctx.db.schema
.dropSchema('pets')

testSql(builder, dialect, {
postgres: {
sql: `drop schema "pets"`,
parameters: [],
},
mysql: {
sql: "drop schema `pets`",
parameters: [],
},
sqlite: NOT_SUPPORTED
})

await builder.execute()
})

it('should drop a schema if exists', async () => {
const builder = ctx.db.schema
.dropSchema('pets')
.ifExists()

testSql(builder, dialect, {
postgres: {
sql: `drop schema if exists "pets"`,
parameters: [],
},
mysql: {
sql: "drop schema if exists `pets`",
parameters: [],
},
sqlite: NOT_SUPPORTED,
})

await builder.execute()
})
}

async function cleanup() {
await ctx.db.schema.dropSchema('pets').ifExists().execute()
}
})

describe('alter table', () => {
beforeEach(async () => {
await ctx.db.schema
Expand Down

0 comments on commit ceb59c3

Please sign in to comment.