Counting items

To get the count of items in the table, just invoke the count method on the Item class, as follows:

let count = try Item.count()print(count)

We hope this helps you to understand how powerful Fluent is and how it uses the ORM technique to map objects into rows in the database to map data from the database into objects used in our program or app. Using Fluent, we can write at a high level and do not need to learn SQL or how to construct queries to perform basic Create, Read, Update, and Delete (CRUD) actions.

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.