UNPKG

@tonyism1/db-utils

Version:

MySQL utilities with automatic table and column creation, plus B2 Backblaze media storage

19 lines (17 loc) 531 B
export function detectType(value) { if (typeof value === "string") return "VARCHAR(255)"; if (typeof value === "number") return "INT"; if (typeof value === "boolean") return "TINYINT(1)"; if (typeof value === "object") return "JSON"; return "VARCHAR(255)"; } export function toSnakeCase(str) { return str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`); } export function mapKeysToSnakeCase(obj) { const newObj = {}; for (const key in obj) { newObj[toSnakeCase(key)] = obj[key]; } return newObj; }