by shortrounddev2 · 1y ago · 0 comments
IEnumerable<User> getExpiredUsers(DbSet<User> users)
=> users.Where(u => u.ExpiresAt < DateTime.UtcNow);
Such simple logical expressions (called expression trees) get converted to SQL queriesI'm building a new project, Typegres, on this same philosophy for the modern web stack (TypeScript/PostgreSQL).
We can take your example a step further and blur the lines between database columns and computed business logic, building the "functional core" right in the model:
// This method compiles directly to a SQL expression
class User extends db.User {
isExpired() {
return this.expiresAt.lt(now());
}
}
const expired = await User.where((u) => u.isExpired());
Here's the playground if that looks interesting: https://typegres.com/play/