Temp3¶
environment: production
your_command > /dev/null 2>&1 &
https://zenn.dev/solvio/articles/5675473b392b7f
cloudwatch alarmでamazon kendraの"IndexDocumentCount"メトリクスが"ProvisionedIndexDocumentCount"メトリクスの90%に達した場合にalarm状態にする設定はできますか?
import mysql from 'mysql2/promise'; const BATCH_SIZE = 1000; async function deleteRowsInBatches(ids: number[]) { const conn = await mysql.createConnection({ host: 'localhost', user: 'your_user', password: 'your_pass', database: 'your_db', }); try { for (let i = 0; i < ids.length; i += BATCH_SIZE) { const batch = ids.slice(i, i + BATCH_SIZE); const placeholders = batch.map(() => '?').join(','); const sql = `DELETE FROM your_table WHERE id IN (${placeholders})`; await conn.execute(sql, batch); console.log(`Deleted batch: ${i} - ${i + batch.length - 1}`); } } finally { await conn.end(); } }
import mysql from 'mysql2/promise'; // DB接続設定 const pool = mysql.createPool({ host: 'localhost', user: 'your_user', password: 'your_password', database: 'your_db', waitForConnections: true, connectionLimit: 10, }); // UPSERT対象データ const users = [ { id: 1, name: 'Alice', email: 'alice@example.com' }, { id: 2, name: 'Bob', email: 'bob@example.com' }, { id: 3, name: 'Charlie', email: 'charlie@example.com' }, ]; async function upsertUsers() { const connection = await pool.getConnection(); try { const columns = ['id', 'name', 'email']; const placeholders = users.map(() => '(?, ?, ?)').join(', '); const values = users.flatMap(user => [user.id, user.name, user.email]); // MySQL 8では VALUES(col) の代わりにエイリアスを使用 const updateClause = columns .filter(col => col !== 'id') // 主キー以外を更新 .map(col => `${col} = new.${col}`) .join(', '); const sql = ` INSERT INTO users (${columns.join(', ')}) VALUES ${placeholders} AS new ON DUPLICATE KEY UPDATE ${updateClause}; `; const [result] = await connection.execute(sql, values); console.log('Upsert result:', result); } finally { connection.release(); } } upsertUsers().catch(console.error);
const input: any = "2025-07-09T12:34:56Z"; // any型の変数(例) let dateValue: Date | null = null; if (typeof input === "string") { const parsedDate = new Date(input); if (!isNaN(parsedDate.getTime())) { dateValue = parsedDate; } } console.log(dateValue);