Skip to content

Commit b00a4da

Browse files
authored
Complete SELECT aliases in ORDER BY and HAVING (#2)
Complete SELECT aliases in ORDER BY and HAVING
2 parents 4ca8e47 + fc2596e commit b00a4da

12 files changed

Lines changed: 120 additions & 15 deletions

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A desktop SQL learning workspace that brings local SQLite, an AI tutor, visual s
1010

1111
<p align="center"><a href="https://github.com/canyrtcn/PractiSQL/releases"><img src="docs/assets/download-windows.en.svg" width="328" height="64" alt="Download PractiSQL for Windows"></a></p>
1212

13-
<p align="center"><strong>Windows x64 · v3.4.269</strong> · <strong>macOS is in preparation.</strong></p>
13+
<p align="center"><strong>Windows x64 · v3.4.270</strong> · <strong>macOS is in preparation.</strong></p>
1414

1515
The button opens Releases, where the Windows x64 installer is available. No GitHub account is required to download it.
1616

@@ -184,7 +184,7 @@ Choose an available model entry in your account. Model names and access can vary
184184
3. Load a supported database or file, or open a built-in learning example. Start writing and running SQL immediately.
185185
4. Connect AI when you want guided explanations, generated queries or AI-backed learning workflows. You can leave this step for later.
186186

187-
[Release notes](docs/releases/v3.4.269.md) · [Build from source](#development-and-repository-layout)
187+
[Release notes](docs/releases/v3.4.270.md) · [Build from source](#development-and-repository-layout)
188188

189189
## More screens and documentation
190190

‎README.tr.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Yerel SQLite, AI öğretmen, görsel şema ve uygulamalı öğrenmeyi, bu akış
1010

1111
<p align="center"><a href="https://github.com/canyrtcn/PractiSQL/releases"><img src="docs/assets/download-windows.tr.svg" width="328" height="64" alt="Windows için PractiSQL indir"></a></p>
1212

13-
<p align="center"><strong>Windows x64 · v3.4.269</strong> · <strong>macOS hazırlanıyor.</strong></p>
13+
<p align="center"><strong>Windows x64 · v3.4.270</strong> · <strong>macOS hazırlanıyor.</strong></p>
1414

1515
Düğme, Windows x64 kurucusunun bulunduğu Releases sayfasını açar. İndirmek için GitHub hesabı gerekmez.
1616

@@ -182,7 +182,7 @@ Hesabında kullanılabilen model seçeneğini kullan. Model adları ve erişim d
182182
3. Desteklenen veritabanını veya dosyanı yükle ya da hazır bir öğrenme örneği aç. SQL yazmaya ve çalıştırmaya hemen başlayabilirsin.
183183
4. Açıklama, sorgu üretimi veya AI destekli öğrenme akışları istediğinde AI bağlantısı ekle. Bu adımı sonraya bırakabilirsin.
184184

185-
[Sürüm notları](docs/releases/v3.4.269.md) · [Kaynaktan çalıştır](#geliştirme-ve-repo-düzeni)
185+
[Sürüm notları](docs/releases/v3.4.270.md) · [Kaynaktan çalıştır](#geliştirme-ve-repo-düzeni)
186186

187187
## Daha fazla ekran ve belge
188188

‎app/renderer/sql-completion.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
const joins=['JOIN','LEFT JOIN','INNER JOIN','CROSS JOIN','RIGHT JOIN','FULL JOIN'];
1313
const followingSource=['WHERE',...joins,'GROUP BY','ORDER BY','LIMIT'];
1414
const followingPredicate=['AND','OR','GROUP BY','ORDER BY','LIMIT'];
15+
function outputAliases(tokens,position){
16+
// Projection names belong to one SELECT, never a CTE, sibling or UNION arm.
17+
if(tokens.some(token=>is(token,'UNION','INTERSECT','EXCEPT')))return [];
18+
const begin=tokens.findLastIndex(token=>token.start<position&&is(token,'SELECT'));if(begin<0)return [];
19+
const finish=tokens.findIndex((token,index)=>index>begin&&is(token,'FROM','WHERE','GROUP','HAVING','ORDER','LIMIT','WINDOW'));
20+
const projection=tokens.slice(begin+1,finish<0?undefined:finish),groups=[[]];
21+
for(const token of projection){if(token.value===','&&!token.quoted)groups.push([]);else groups.at(-1).push(token);}
22+
const names=[];
23+
for(const group of groups){
24+
const alias=group.at(-1),previous=group.at(-2);if(!alias||!previous||alias.string||!alias.quoted&&(!/^[\p{L}_][\p{L}\p{N}_$]*$/u.test(alias.value)||reserved.has(alias.upper)))continue;
25+
const explicit=is(previous,'AS')&&group.length>2;
26+
const implicit=!is(previous,'AS','COLLATE')&&previous.end<alias.start&&(previous.quoted||previous.value===')'||is(previous,'END')||/^[\p{L}\p{N}_]/u.test(previous.value)&&!reserved.has(previous.upper));
27+
if(explicit||implicit)names.push(alias.value);
28+
}
29+
return names.filter((name,index)=>names.findIndex(other=>other.toLowerCase()===name.toLowerCase())===index&&names.filter(other=>other.toLowerCase()===name.toLowerCase()).length===1).map(spelling);
30+
}
1531
function joinCondition(a,b){
1632
const possibilities=[];
1733
for(const [child,parent]of [[a,b],[b,a]]){
@@ -110,7 +126,8 @@
110126
const qualifier=last?.value==='.'?tokens.at(-2)?.value:null;
111127
const wildcard=upper==='*'&&(is(tokens.at(-2),'SELECT','DISTINCT')||tokens.at(-2)?.value==='.'||clause==='SELECT'&&!insideExpression&&tokens.at(-2)?.value===',');
112128
const operand=last&&(wildcard||last.quoted||last.value===')'||is(last,'END','NULL','TRUE','FALSE')||/^[\p{L}\p{N}_]/u.test(last.value)&&!reserved.has(last.upper));
113-
const expression=[...columnNames,...funcs,'CASE','NULL'];
129+
const aliases=!windowScope&&['ORDER','HAVING'].includes(clause)?outputAliases(allSame,position):[];
130+
const expression=[...aliases,...columnNames,...funcs,'CASE','NULL'];
114131
const frame=windowScope&&['ROWS','RANGE','GROUPS'].includes(clause);
115132
const frameTokens=frame?local.slice(local.findLastIndex(t=>is(t,'ROWS','RANGE','GROUPS'))+1):[];
116133
const frameBetween=frameTokens.some(t=>is(t,'BETWEEN')),frameEnd=frameTokens.some(t=>is(t,'AND'));

‎docs/architecture/architecture.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"version": "3.4.269",
3-
"date": "2026-10-21",
2+
"version": "3.4.270",
3+
"date": "2026-10-27",
44
"defaultLocale": "en",
55
"views": [
66
{
@@ -1159,7 +1159,7 @@
11591159
"references": {
11601160
".github/SECURITY.md": "470353c7e0447bd45fea3e4040507f03253c3cc762bac12ed424e9f6f93d648d",
11611161
"LICENSE": "c03af9304b8b44d8f65921a325a7f2077ebb89e5c64fc309106b3c547ef02d09",
1162-
"README.md": "05a90e92c8829fe475fec2b158fb8c3f4a1b110940230caf1266486a49d24200",
1162+
"README.md": "74e2b60b292faa39f6624a22429f01d9e234a993e9056ad889ecfb320e20281c",
11631163
"app/ai-rate-limit.js": "fdf24873dfb664444f28728abe483a3f363e3aa61d16201a2cb1429ef67a2ff8",
11641164
"app/chatgpt-account.js": "1ea42388b92788b93804a9f0b6fc3441039ce26af2b837e9e5e732c160a99f32",
11651165
"app/database-inspection/runner.cjs": "32265046ec123e4248845436a523f67ff069bb7ebd8bb83102fc43e249d11d20",

‎docs/architecture/index.html‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎docs/architecture/request-flow.en.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎docs/architecture/request-flow.tr.svg‎

Lines changed: 1 addition & 1 deletion
Loading

‎docs/releases/v3.4.270.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### English
2+
3+
- Local SQL completion now recognizes SELECT output aliases in `ORDER BY` and `HAVING`, including quoted names and aggregate expressions. Suggestions stay within the current SELECT scope and preserve SQL after the cursor.
4+
5+
Windows x64: download **Setup.exe** below. **.blockmap** and **latest.yml** support in-app updates; they do not need to be opened manually.
6+
7+
### Türkçe
8+
9+
- Yerel SQL tamamlama, SELECT sonuç takma adlarını artık `ORDER BY` ve `HAVING` içinde tanır. Tırnaklı isimler ve toplama fonksiyonları desteklenir; öneriler mevcut SELECT kapsamını ve imleçten sonraki SQL'i korur.
10+
11+
Windows x64 için aşağıdaki **Setup.exe** kurucusunu indirin. **.blockmap** ve **latest.yml** uygulama içi güncellemeyi destekler; bunları elle açmanız gerekmez.

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "practisql",
3-
"version": "3.4.269",
3+
"version": "3.4.270",
44
"description": "PractiSQL — AI-powered SQL playground.",
55
"main": "app/main.js",
66
"build": {
@@ -82,7 +82,7 @@
8282
"test:workshop": "node scripts/test-home-workshop.cjs",
8383
"test:interface-details": "node scripts/test-interface-details.cjs",
8484
"editor:build": "node scripts/build-sql-editor.cjs",
85-
"test:editor": "node --test scripts/test-editor-policy.cjs scripts/test-sql-completion-context.cjs scripts/test-sql-highlight.cjs && node scripts/test-editor-ui.cjs && node scripts/test-sql-completion-ui.cjs && node scripts/test-workspace-responsiveness.cjs",
85+
"test:editor": "node --test scripts/test-editor-policy.cjs scripts/test-sql-completion-context.cjs scripts/test-sql-output-aliases.cjs scripts/test-sql-highlight.cjs && node scripts/test-editor-ui.cjs && node scripts/test-sql-completion-ui.cjs && node scripts/test-workspace-responsiveness.cjs",
8686
"test:layout": "node --test scripts/test-window-layout.cjs scripts/test-interface-scale.cjs",
8787
"postinstall": "node scripts/prepare-runtime.cjs",
8888
"docs:assets": "node scripts/build-repository-assets.cjs",

0 commit comments

Comments
 (0)