EzyData: Default Functions
Updated at 1685687175000Function | Description | |
1 | save | Save one or an array or a list of entities |
2 | findAll | Find all entities or a list of entities by skip an limit |
3 | findById | Find an entity by id |
4 | findByIdOptional | Find an entity by id and return an optional |
5 | findListByIds | Find a list of entities by a list of ids |
6 | findByField | Find an entity by field's name and field's value |
7 | findByFieldOptional | Find an entity by field's name and field's value and return an optional |
8 | findListByField | Find a list of entities by field's name and field's value |
9 | containsById | Check contains an entity or not by id |
10 | containsByField | Check contains an entity by field's name and field's value and return an optional |
11 | count | Count all entities |
12 | deleteAll | Delete all entities |
13 | delete | Delete an entity by id |
14 | deleteByIds | Delete a list of entities by ids |
1. Save
You can save one or multi entities like this:
// save one book bookRepository.save(book); // save an array of books bookRepository.save(book1, book2); // save a list of books bookRepository.save(bookList);
2. FindAll
You can find all entities like this:
// find all books List allBooks = bookRepository.findAll(); // skip 10 first books and take 10 books List allBooks = bookRepository.findAll(10, 10);
3. FindById
You can find a entity by id like this:
Book book = bookRepository.findById(bookId);
4. FindByIdOptional
If you don't want to check null, you can find an entity by id an return an Optional like this:
Optional bookOptional = bookRepository.findByIdOptional(bookId);
5. FindListByIds
You can find a list of entities by a collection of ids like this:
List books = bookRepository.findListByIds(ids);
6. FindByField
You can find an entity by a field name and value like this:
Book book = bookRepository.findByField("name", "bookName");
7. FindByFieldOptional
If you don't want to check null, you can find an entity by a field name and value an return an Optional like this:
Optional bookOptional = bookRepository.findByFieldOptional("name", "bookName");
8. FindListByField
You can find a list of entities by a field name and value like this:
// find all books have the field value List books = bookRepository.findListByField( "name", "bookName" ); // find books have the field value, skip 10 first books and take 10 books List books = bookRepository.findListByField( "name", "bookName", 10, 10 );
9. ContainsById
You can check an entity exists or not by id like this:
boolean isBookExisting = bookRepository.containsById(bookId);
10. ContainsByField
You can check an entity exists or not by a field name and value like this:
boolean isBookExisting = bookRepository.containsByField("name", "bookName");
11. Count
You can count all entities like this:
long bookCount = bookRepository.count();
12. DeleteAll
You can delete all entities like this:
bookRepository.deleteAll();
13. Delete
You can delete an entity by an id like this:
bookRepository.delete(bookId);
14. DeleteByIds
You can delete a list of entities that have id in a id list like this:
bookRepository.deleteByIds(bookIds);
Examples
- Book management with MongoDB: an example for mongodb.
- Book management with JPA: an example for JPA and MySQL.