Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return policy.db.tx(async t => {
const { name, schemaName, tableName } = policy;
const dropNames = { name, schemaName, tableName };
await t.none(`drop policy if exists $(name:name) on $(schemaName:name).$(tableName:name);`, dropNames);
const names = { name: dataForUpdate.name, schemaName, tableName };
const policyQueryPart = formatQuery('$(name:name) on $(schemaName:name).$(tableName:name)', names);
const typeQueryPart = dataForUpdate.permissive ? '' : 'as restrictive';
const commandAndRoles = {
command: dataForUpdate.command,
roles: dataForUpdate.roles,
};
const forQueryPart = formatQuery(`for $(command:raw) to $(roles:name)`, commandAndRoles);
const qualifierQueryPart = dataForUpdate.qualifier ? `using (${dataForUpdate.qualifier})` : '';
const checkQueryPart = dataForUpdate.check ? `with check (${dataForUpdate.check})` : '';
await t.none(
`create policy ${policyQueryPart} ${typeQueryPart} ${forQueryPart} ${qualifierQueryPart} ${checkQueryPart};`
);
});
},
return policy.db.tx(async t => {
const { name, schemaName, tableName } = policy;
const dropNames = { name, schemaName, tableName };
await t.none(`drop policy if exists $(name:name) on $(schemaName:name).$(tableName:name);`, dropNames);
const names = { name: dataForUpdate.name, schemaName, tableName };
const policyQueryPart = formatQuery('$(name:name) on $(schemaName:name).$(tableName:name)', names);
const typeQueryPart = dataForUpdate.permissive ? '' : 'as restrictive';
const commandAndRoles = {
command: dataForUpdate.command,
roles: dataForUpdate.roles,
};
const forQueryPart = formatQuery(`for $(command:raw) to $(roles:name)`, commandAndRoles);
const qualifierQueryPart = dataForUpdate.qualifier ? `using (${dataForUpdate.qualifier})` : '';
const checkQueryPart = dataForUpdate.check ? `with check (${dataForUpdate.check})` : '';
await t.none(
`create policy ${policyQueryPart} ${typeQueryPart} ${forQueryPart} ${qualifierQueryPart} ${checkQueryPart};`
);
});