-
Notifications
You must be signed in to change notification settings - Fork 279
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
183 additions
and
33 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
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,12 @@ | ||
import { | ||
OnCommitAction, | ||
ON_COMMIT_ACTIONS, | ||
} from '../operation-node/create-table-node.js' | ||
|
||
export function parseOnCommitAction(action: OnCommitAction): OnCommitAction { | ||
if (ON_COMMIT_ACTIONS.includes(action)) { | ||
return action | ||
} | ||
|
||
throw new Error(`invalid OnCommitAction ${action}`) | ||
} |
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,14 @@ | ||
import { | ||
OnModifyForeignAction, | ||
ON_MODIFY_FOREIGN_ACTIONS, | ||
} from '../operation-node/references-node.js' | ||
|
||
export function parseOnModifyForeignAction( | ||
action: OnModifyForeignAction | ||
): OnModifyForeignAction { | ||
if (ON_MODIFY_FOREIGN_ACTIONS.includes(action)) { | ||
return action | ||
} | ||
|
||
throw new Error(`invalid OnModifyForeignAction ${action}`) | ||
} |
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
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
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,74 @@ | ||
import { Updateable } from '../../../dist/cjs' | ||
|
||
import { | ||
BUILT_IN_DIALECTS, | ||
destroyTest, | ||
initTest, | ||
TestContext, | ||
Person, | ||
testSql, | ||
} from './test-setup.js' | ||
|
||
for (const dialect of BUILT_IN_DIALECTS) { | ||
describe(`${dialect}: sanitize identifiers`, () => { | ||
let ctx: TestContext | ||
|
||
before(async function () { | ||
ctx = await initTest(this, dialect) | ||
}) | ||
|
||
after(async () => { | ||
await destroyTest(ctx) | ||
}) | ||
|
||
it('should escape identifier quotes', async () => { | ||
const obj: Record<string, unknown> = { | ||
first_name: 'foo', | ||
'last_name"`': 'bar', | ||
} | ||
|
||
const person = obj as unknown as Updateable<Person> | ||
const query = ctx.db.updateTable('person').set(person) | ||
|
||
testSql(query, dialect, { | ||
postgres: { | ||
sql: 'update "person" set "first_name" = $1, "last_name""`" = $2', | ||
parameters: ['foo', 'bar'], | ||
}, | ||
mysql: { | ||
sql: 'update `person` set `first_name` = ?, `last_name"``` = ?', | ||
parameters: ['foo', 'bar'], | ||
}, | ||
sqlite: { | ||
sql: 'update "person" set "first_name" = ?, "last_name""`" = ?', | ||
parameters: ['foo', 'bar'], | ||
}, | ||
}) | ||
}) | ||
|
||
it('should escape multiple identifier quotes', async () => { | ||
const obj: Record<string, unknown> = { | ||
first_name: 'foo', | ||
'last_name""``': 'bar', | ||
} | ||
|
||
const person = obj as unknown as Updateable<Person> | ||
const query = ctx.db.updateTable('person').set(person) | ||
|
||
testSql(query, dialect, { | ||
postgres: { | ||
sql: 'update "person" set "first_name" = $1, "last_name""""``" = $2', | ||
parameters: ['foo', 'bar'], | ||
}, | ||
mysql: { | ||
sql: 'update `person` set `first_name` = ?, `last_name""````` = ?', | ||
parameters: ['foo', 'bar'], | ||
}, | ||
sqlite: { | ||
sql: 'update "person" set "first_name" = ?, "last_name""""``" = ?', | ||
parameters: ['foo', 'bar'], | ||
}, | ||
}) | ||
}) | ||
}) | ||
} |
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