Elysia Tools
Navegação
Segurança
Parâmetros SQL e limites
Praticar descritor SQL fixo, limite e rótulos de ordem predefinidos sem banco.
Exemplos
Entradas desta coleção
Separar instrução e valor
Criar descritor fixo com valor separado, sem banco de dados.
// Local training descriptor only; no database driver or execution.
function titleLookup(title) {
if (typeof title !== 'string' || title.length > 40) return null;
return { statement: 'SELECT title FROM training_books WHERE title = ?', values: [title] };
}
const result = titleLookup('Blue Notebook');
console.log(JSON.stringify(result));Limitar quantidade exibida
Limitar inteiros a 1–20; usar 10 nos demais casos, só número local.
function displayLimit(value) {
return Number.isInteger(value) ? Math.max(1, Math.min(20, value)) : 10;
}
const result = [0, 7, 99, 2.5].map(displayLimit);
console.log(JSON.stringify(result));Escolher rótulo fixo
Mapear opções conhecidas, senão title; nenhuma instrução é montada.
function sortLabel(option) {
const labels = new Map([['title', 'title'], ['year', 'published_year']]);
return labels.get(option) ?? 'title';
}
const result = ['year', 'other'].map(sortLabel);
console.log(JSON.stringify(result));Ferramentas
Ferramentas frequentemente usadas com este exemplo
Relacionado
Coleções de exemplos relacionadas
Relacionado