Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the query builder immutable #7

Open
baukevdw opened this issue Aug 31, 2020 · 0 comments · May be fixed by #9
Open

Make the query builder immutable #7

baukevdw opened this issue Aug 31, 2020 · 0 comments · May be fixed by #9
Assignees
Labels
enhancement New feature or request

Comments

@baukevdw
Copy link
Member

baukevdw commented Aug 31, 2020

Making the query builder immutable makes code safer and allows the user to write cleaner code.

<?php
/** @var \Neat\Database\Connection $db */
$query = new \Neat\Database\Query($db);

$usersQuery         = $query->from('user', 'u');
$totalUsers         = $usersQuery->select('COUNT(1)')->query()->value();
$users              = $usersQuery->select('u.*')->limit(5)->query()->rows();
$activeUsersQuery   = $usersQuery->where(['active' => true]);
$totalActiveUsers   = $activeUsersQuery->select('COUNT(1)')->query()->value();
$activeRoles        = $activeUsersQuery->select('DISTINCT u.role')->query()->values();
$activeUsers        = $activeUsersQuery->select('u.*')->limit(5)->query()->rows();

Making the query builder immutable might break code so we'll need an upgrade path:
1.x release:

  • Introduce QueryBuilderInterface
  • Introduce ImmutableQuery implements QueryBuilderInterface
  • Introduce MutableQuery extends Query implements QueryBuilderInterface
  • Deprecate Query

2.0 release:

  • Query will be immutable
  • ImmutableQuery will extend Query
@baukevdw baukevdw added the enhancement New feature or request label Aug 31, 2020
baukevdw added a commit that referenced this issue Feb 12, 2021
@baukevdw baukevdw self-assigned this Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant