EzyData: Default Functions

Updated at 1685687175000
EzyDatabase provides a list of functions:

FunctionDescription
1saveSave one or an array or a list of entities
2findAllFind all entities or a list of entities by skip an limit
3findByIdFind an entity by id
4findByIdOptionalFind an entity by id and return an optional
5findListByIdsFind a list of entities by a list of ids
6findByFieldFind an entity by field's name and field's value
7findByFieldOptionalFind an entity by field's name and field's value and return an optional
8findListByFieldFind a list of entities by field's name and field's value
9containsByIdCheck contains an entity or not by id
10containsByFieldCheck contains an entity by field's name and field's value and return an optional
11countCount all entities
12deleteAllDelete all entities
13deleteDelete an entity by id
14deleteByIdsDelete 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

  1. Book management with MongoDB: an example for mongodb.
  2. Book management with JPA: an example for JPA and MySQL.