crud
This commit is contained in:
@@ -62,8 +62,24 @@ class NoteDatabase {
|
|||||||
await fillDemoData(database, version);
|
await fillDemoData(database, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future fillDemoData(Database database, int version) async {
|
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
|
// Add fake categories
|
||||||
await database.execute('''
|
await database.execute('''
|
||||||
INSERT INTO note (
|
INSERT INTO note (
|
||||||
@@ -80,7 +96,6 @@ class NoteDatabase {
|
|||||||
)
|
)
|
||||||
''');
|
''');
|
||||||
|
|
||||||
|
|
||||||
await database.execute('''
|
await database.execute('''
|
||||||
INSERT INTO note (
|
INSERT INTO note (
|
||||||
title,
|
title,
|
||||||
@@ -160,7 +175,6 @@ class NoteDatabase {
|
|||||||
database.close();
|
database.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<void> deleteDatabase() async {
|
Future<void> deleteDatabase() async {
|
||||||
final databasePath = await getDatabasesPath();
|
final databasePath = await getDatabasesPath();
|
||||||
final path = join(databasePath, 'note.db');
|
final path = join(databasePath, 'note.db');
|
||||||
@@ -177,28 +191,6 @@ class NoteDatabase {
|
|||||||
return database.isOpen;
|
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 {
|
Future<List<Map>> selectAllPromemoria() async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
|
|
||||||
@@ -207,7 +199,6 @@ class NoteDatabase {
|
|||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<List<Map>> selectAllNotes() async {
|
Future<List<Map>> selectAllNotes() async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
|
|
||||||
@@ -216,35 +207,27 @@ class NoteDatabase {
|
|||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> createNote(Database database, Note note) async {
|
||||||
|
await database.insert(
|
||||||
|
'note',
|
||||||
|
note.toMap(),
|
||||||
|
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||||
|
);
|
||||||
|
|
||||||
Future<void> createPromemoria(Database database,
|
print('note $note.title inserted');
|
||||||
Promemoria promemoria) async {
|
}
|
||||||
await database.execute('''
|
|
||||||
INSERT INTO promemoria (
|
Future<void> createPromemoria(
|
||||||
title,
|
Database database, Promemoria promemoria) async {
|
||||||
creationDate,
|
await database.insert(
|
||||||
lastModificationDate,
|
'promemoria',
|
||||||
expirationDate,
|
promemoria.toMap(),
|
||||||
arrayPromemoria,
|
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||||
description,
|
);
|
||||||
priority,
|
|
||||||
color
|
|
||||||
) VALUES (
|
|
||||||
'$promemoria.title',
|
|
||||||
'$promemoria.creationDate',
|
|
||||||
'$promemoria.lastModificationDate',
|
|
||||||
'$promemoria.expirationDate',
|
|
||||||
'$promemoria.arrayPromemoria.toString()',
|
|
||||||
'$promemoria.description',
|
|
||||||
'$promemoria.priority',
|
|
||||||
'$promemoria.color'
|
|
||||||
)
|
|
||||||
''');
|
|
||||||
|
|
||||||
print('promemoria $promemoria.title inserted');
|
print('promemoria $promemoria.title inserted');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<Map<String, Object?>> readPromemoria(int id) async {
|
Future<Map<String, Object?>> readPromemoria(int id) async {
|
||||||
final db = await database;
|
final db = await database;
|
||||||
|
|
||||||
@@ -252,23 +235,25 @@ class NoteDatabase {
|
|||||||
return results.first;
|
return results.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<Map<String, Object?>> readNote(int id) async {
|
Future<Map<String, Object?>> readNote(int id) async {
|
||||||
final db = await database;
|
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;
|
return results.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Future<void> updatePromemoria(Promemoria promemoria) async {
|
Future<void> updatePromemoria(Promemoria promemoria) async {
|
||||||
// final db = await database;
|
final db = await database;
|
||||||
|
|
||||||
//await db.update('promemoria', promemoria, where: 'id = ?',
|
await db.update('promemoria', promemoria.toMap(),
|
||||||
// Pass the Dog's id as a whereArg to prevent SQL injection.
|
where: 'id = ?', whereArgs: [promemoria.getId()]);
|
||||||
// whereArgs: [dog.id],)
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
|
Future<void> updateNote(Note note) async {
|
||||||
|
final db = await database;
|
||||||
|
|
||||||
|
await db.update('note', note.toMap(),
|
||||||
|
where: 'id = ?', whereArgs: [note.getId()]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,63 @@ class Note extends BaseEntity {
|
|||||||
static String lastModificationDate = BaseEntity.getLastEditDate;
|
static String lastModificationDate = BaseEntity.getLastEditDate;
|
||||||
static String arrayPromemoria = '';
|
static String arrayPromemoria = '';
|
||||||
static String description = '';
|
static String description = '';
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {'id': id, 'title': title, 'desc': description,'CreationDate': creationDate, 'lastM': lastModificationDate };
|
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 arrayPromemoria = '';
|
||||||
static String description = '';
|
static String description = '';
|
||||||
static Priority priority = Priority.none;
|
static Priority priority = Priority.none;
|
||||||
|
|
||||||
static Color color = Color.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