crud
This commit is contained in:
@@ -62,8 +62,24 @@ class NoteDatabase {
|
||||
await fillDemoData(database, version);
|
||||
}
|
||||
|
||||
|
||||
Future fillDemoData(Database database, int version) async {
|
||||
|
||||
var nota = Note();
|
||||
nota.setTitle("Nota 1");
|
||||
nota.setCreationDate("2023-09-56");
|
||||
nota.setLastModificationDate("2023-09-56");
|
||||
nota.setArrayPromemoria("1,2,3,4,5");
|
||||
nota.setDescription("Questo è un esempio di nota 1.");
|
||||
|
||||
await createNote(database, nota);
|
||||
|
||||
print(await readNote(1));
|
||||
|
||||
nota.setDescription("ciao");
|
||||
await updateNote (nota);
|
||||
|
||||
print(await readNote (1));
|
||||
|
||||
// Add fake categories
|
||||
await database.execute('''
|
||||
INSERT INTO note (
|
||||
@@ -80,7 +96,6 @@ class NoteDatabase {
|
||||
)
|
||||
''');
|
||||
|
||||
|
||||
await database.execute('''
|
||||
INSERT INTO note (
|
||||
title,
|
||||
@@ -160,7 +175,6 @@ class NoteDatabase {
|
||||
database.close();
|
||||
}
|
||||
|
||||
|
||||
Future<void> deleteDatabase() async {
|
||||
final databasePath = await getDatabasesPath();
|
||||
final path = join(databasePath, 'note.db');
|
||||
@@ -177,28 +191,6 @@ class NoteDatabase {
|
||||
return database.isOpen;
|
||||
}
|
||||
|
||||
|
||||
Future<void> createNote(Database database, Note note) async {
|
||||
await database.execute('''
|
||||
INSERT INTO note (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
arrayPromemoria,
|
||||
description,
|
||||
|
||||
) VALUES (
|
||||
'$note.title}',
|
||||
'$note.creationDate',
|
||||
'$note.lastModificationDate',
|
||||
'$note.arrayPromemoria.toString()',
|
||||
'$note.description',
|
||||
)
|
||||
''');
|
||||
|
||||
print('note $note.title inserted');
|
||||
}
|
||||
|
||||
Future<List<Map>> selectAllPromemoria() async {
|
||||
final db = await database;
|
||||
|
||||
@@ -207,7 +199,6 @@ class NoteDatabase {
|
||||
return maps;
|
||||
}
|
||||
|
||||
|
||||
Future<List<Map>> selectAllNotes() async {
|
||||
final db = await database;
|
||||
|
||||
@@ -216,35 +207,27 @@ class NoteDatabase {
|
||||
return maps;
|
||||
}
|
||||
|
||||
Future<void> createNote(Database database, Note note) async {
|
||||
await database.insert(
|
||||
'note',
|
||||
note.toMap(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
|
||||
Future<void> createPromemoria(Database database,
|
||||
Promemoria promemoria) async {
|
||||
await database.execute('''
|
||||
INSERT INTO promemoria (
|
||||
title,
|
||||
creationDate,
|
||||
lastModificationDate,
|
||||
expirationDate,
|
||||
arrayPromemoria,
|
||||
description,
|
||||
priority,
|
||||
color
|
||||
) VALUES (
|
||||
'$promemoria.title',
|
||||
'$promemoria.creationDate',
|
||||
'$promemoria.lastModificationDate',
|
||||
'$promemoria.expirationDate',
|
||||
'$promemoria.arrayPromemoria.toString()',
|
||||
'$promemoria.description',
|
||||
'$promemoria.priority',
|
||||
'$promemoria.color'
|
||||
)
|
||||
''');
|
||||
print('note $note.title inserted');
|
||||
}
|
||||
|
||||
Future<void> createPromemoria(
|
||||
Database database, Promemoria promemoria) async {
|
||||
await database.insert(
|
||||
'promemoria',
|
||||
promemoria.toMap(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
|
||||
print('promemoria $promemoria.title inserted');
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, Object?>> readPromemoria(int id) async {
|
||||
final db = await database;
|
||||
|
||||
@@ -252,23 +235,25 @@ class NoteDatabase {
|
||||
return results.first;
|
||||
}
|
||||
|
||||
|
||||
Future<Map<String, Object?>> readNote(int id) async {
|
||||
final db = await database;
|
||||
|
||||
final results= await db.query('SELECT * FROM promemoria where id=$id');
|
||||
final results = await db.query('SELECT * FROM promemoria where id=$id');
|
||||
|
||||
return results.first;
|
||||
}
|
||||
|
||||
// Future<void> updatePromemoria(Promemoria promemoria) async {
|
||||
// final db = await database;
|
||||
Future<void> updatePromemoria(Promemoria promemoria) async {
|
||||
final db = await database;
|
||||
|
||||
//await db.update('promemoria', promemoria, where: 'id = ?',
|
||||
// Pass the Dog's id as a whereArg to prevent SQL injection.
|
||||
// whereArgs: [dog.id],)
|
||||
//}
|
||||
await db.update('promemoria', promemoria.toMap(),
|
||||
where: 'id = ?', whereArgs: [promemoria.getId()]);
|
||||
}
|
||||
|
||||
Future<void> updateNote(Note note) async {
|
||||
final db = await database;
|
||||
|
||||
await db.update('note', note.toMap(),
|
||||
where: 'id = ?', whereArgs: [note.getId()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,63 @@ class Note extends BaseEntity {
|
||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||
static String arrayPromemoria = '';
|
||||
static String description = '';
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'creationDate': creationDate,
|
||||
'lastModificationDate': lastModificationDate,
|
||||
'arrayPromemoria': arrayPromemoria,
|
||||
'description': description
|
||||
};
|
||||
}
|
||||
|
||||
String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void setId(String id) {
|
||||
id = id;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
title = title;
|
||||
}
|
||||
|
||||
String getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
void setCreationDate(String creationDate) {
|
||||
creationDate = creationDate;
|
||||
}
|
||||
|
||||
String getLastModificationDate() {
|
||||
return lastModificationDate;
|
||||
}
|
||||
|
||||
void setLastModificationDate(String lastModificationDate) {
|
||||
lastModificationDate = lastModificationDate;
|
||||
}
|
||||
|
||||
String getArrayPromemoria() {
|
||||
return arrayPromemoria;
|
||||
}
|
||||
|
||||
void setArrayPromemoria(String arrayPromemoria) {
|
||||
arrayPromemoria = arrayPromemoria;
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
void setDescription(String description) {
|
||||
description = description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,85 @@ class Promemoria extends BaseEntity {
|
||||
static String arrayPromemoria = '';
|
||||
static String description = '';
|
||||
static Priority priority = Priority.none;
|
||||
|
||||
static Color color = Color.none;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'creationDate': creationDate,
|
||||
'lastModificationDate': lastModificationDate,
|
||||
'expirationDate': expirationDate,
|
||||
'arrayPromemoria': arrayPromemoria,
|
||||
'description': description,
|
||||
'priority': priority,
|
||||
'color': color,
|
||||
};
|
||||
}
|
||||
|
||||
String getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
void setId(String id) {
|
||||
id = id;
|
||||
}
|
||||
|
||||
String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
title = title;
|
||||
}
|
||||
|
||||
String getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
void setCreationDate(String creationDate) {
|
||||
creationDate = creationDate;
|
||||
}
|
||||
|
||||
String getLastModificationDate() {
|
||||
return lastModificationDate;
|
||||
}
|
||||
|
||||
void setLastModificationDate(String lastModificationDate) {
|
||||
lastModificationDate = lastModificationDate;
|
||||
}
|
||||
|
||||
String getExpirationDate() {
|
||||
return expirationDate;
|
||||
}
|
||||
|
||||
void setExpirationDate(String expirationDate) {
|
||||
expirationDate = expirationDate;
|
||||
}
|
||||
|
||||
String getArrayPromemoria() {
|
||||
return arrayPromemoria;
|
||||
}
|
||||
|
||||
void setArrayPromemoria(String arrayPromemoria) {
|
||||
arrayPromemoria = arrayPromemoria;
|
||||
}
|
||||
|
||||
String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
void setDescription(String description) {
|
||||
description = description;
|
||||
}
|
||||
|
||||
Priority getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
void setPriority(Priority priority) {
|
||||
priority = priority;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user