0 purchases
quds mysql
Quds MySql #
Is an automated version of mysql1!
How to use #
See the ./example directory for an example.
1. To create a model
Model classes should extend DbModel class.
Define the schema of your model
class Note extends DbModel {
var title = StringField(columnName: 'title');
var content = StringField(columnName: 'content');
var isImportant = BoolField(columnName: 'isImportant');
@override
List<FieldWithValue>? getFields() => [title, content, isImportant];
}
copied to clipboard
Note that:
Every model has default fields:
id (Auto incremental integer field)
creationTime (automatically set once when created)
modificationTime (automatically set when created, and with every update operation)
2. To create a table manager
class NotesRepository extends DbRepository<Note> {
NotesRepository() : super(() => Note());
@override
String get tableName => 'Notes';
}
copied to clipboard
As shown, to set the name of the table:
@override
String get tableName => 'Notes';
copied to clipboard
Note that:
In Repository class constructor, you should provide it with model object creation function.
NotesRepository() : super(() => Note());
copied to clipboard
To create a repository instance,
NotesRepository NotesRepository = NotesRepository();
copied to clipboard
3. Crud operations:
Creation: (Insertion)
single:
Note n = Note();
n.title.value = 'New note';
n.content.value = 'Note content, describe your self';
n.isImportant.value = ([true, false]..shuffle()).first;
await NotesRepository.insertEntry(n);
copied to clipboard
multiple:
await NotesRepository.insertCollection([n1,n2,n3,...]);
copied to clipboard
Reading (Query):
var allNotes = await NotesRepository.select();
var importantNotes = await NotesRepository.select(where:(n)=>n.isImportant.isTrue);
var imortantRed = await NotesRepository.select(where:(n)=>n.isImportant.isTrue);
copied to clipboard
Updating:
n.title = 'new title';
await NotesRepository.updateEntry(n);
copied to clipboard
Deletion:
await NotesRepository.deleteEntry(n);
copied to clipboard
Monitoring changes: #
To handle the changes in some table:
NotesRepository.addEntryChangeListner((changeType, entry) {
switch (changeType) {
case EntryChangeType.Insertion:
//New Note added (entry)
break;
case EntryChangeType.Deletion:
//(entry) has been deleted
break;
case EntryChangeType.Modification:
//(entry) has been modified
break;
}
});
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.