UNPKG

@flavoai/fastfold

Version:

Zero-boilerplate backend for React apps with auto-generated CRUD and declarative security

53 lines 1.7 kB
export class BaseDatabaseAdapter { connected = false; ensureConnected() { if (!this.connected) { throw new Error('Database not connected. Call connect() first.'); } } mapFieldType(fieldType) { // Override in specific adapters switch (fieldType) { case 'string': return 'TEXT'; case 'number': return 'REAL'; case 'boolean': return 'BOOLEAN'; case 'date': return 'DATETIME'; case 'json': return 'JSON'; default: return 'TEXT'; } } buildWhereClause(where) { if (!where || Object.keys(where).length === 0) { return { sql: '', values: [] }; } const conditions = []; const values = []; for (const [key, value] of Object.entries(where)) { if (value === null) { conditions.push(`${key} IS NULL`); } else if (Array.isArray(value)) { conditions.push(`${key} IN (${value.map(() => '?').join(', ')})`); values.push(...value); } else { conditions.push(`${key} = ?`); values.push(value); } } return { sql: `WHERE ${conditions.join(' AND ')}`, values }; } buildOrderByClause(orderBy) { if (!orderBy || Object.keys(orderBy).length === 0) { return ''; } const orders = Object.entries(orderBy) .map(([field, direction]) => `${field} ${direction.toUpperCase()}`) .join(', '); return `ORDER BY ${orders}`; } } //# sourceMappingURL=base.js.map