- BD versión 2 con onUpgrade automático desde v1 - Tabla clientes: nombre, teléfono, email, dirección - Tabla suscripciones: cliente_id, servicio, tipo, plan, estado, fechas, monto - Modelo Suscripcion con props calculadas vencida y activa - SuscripcionesDao: getByCliente, getByEstado, getProximasAVencer, cambiarEstado - Seed v2: 3 clientes y 5 suscripciones con estados variados Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
import '../database_helper.dart';
|
|
import '../../models/cliente.dart';
|
|
|
|
class ClientesDao {
|
|
final _db = DatabaseHelper.instance;
|
|
|
|
Future<List<Cliente>> getAll() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('clientes', orderBy: 'nombre ASC');
|
|
return rows.map(Cliente.fromMap).toList();
|
|
}
|
|
|
|
Future<Cliente?> getById(int id) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('clientes', where: 'id = ?', whereArgs: [id]);
|
|
return rows.isEmpty ? null : Cliente.fromMap(rows.first);
|
|
}
|
|
|
|
Future<int> insert(Cliente c) async {
|
|
final db = await _db.db;
|
|
return db.insert('clientes', c.toMap());
|
|
}
|
|
|
|
Future<int> update(Cliente c) async {
|
|
final db = await _db.db;
|
|
return db.update('clientes', c.toMap(),
|
|
where: 'id = ?', whereArgs: [c.id]);
|
|
}
|
|
|
|
Future<int> delete(int id) async {
|
|
final db = await _db.db;
|
|
return db.delete('clientes', where: 'id = ?', whereArgs: [id]);
|
|
}
|
|
|
|
Future<List<Cliente>> getPendientes() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('clientes', where: 'sincronizado = 0');
|
|
return rows.map(Cliente.fromMap).toList();
|
|
}
|
|
}
|