Skip to content

Commit 4fee43d

Browse files
committed
BUG#34947621: fix Table.select() TypeScript definition
The Table.select() method accepts multiple optional arguments which can be used to determine the columns that are included in the result set. However, the TypeScript definition for this method does not specify the possible types of these arguments leading to an error when TypeScript application code is compiled to JavaScript using "tsc" (the TypeScript compiler). This patch updates the TypeScript definition to account for the possible types of any argument provided to the Table.select() method, as established by the X DevAPI specification. https://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tableselectfunction Change-Id: Ie6322ef586aec8e28ffb5c86578dc72270357a85
1 parent f287ec6 commit 4fee43d

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

types/lib/DevAPI/Projecting.d.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License, version 2.0, as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is also distributed with certain software (including
9+
* but not limited to OpenSSL) that is licensed under separate terms,
10+
* as designated in a particular file or component or in included license
11+
* documentation. The authors of MySQL hereby grant you an
12+
* additional permission to link the program and your derivative works
13+
* with the separately licensed software that they have included with
14+
* MySQL.
15+
*
16+
* Without limiting anything contained in the foregoing, this file,
17+
* which is part of MySQL Connector/Node.js, is also subject to the
18+
* Universal FOSS Exception, version 1.0, a copy of which can be found at
19+
* http://oss.oracle.com/licenses/universal-foss-exception.
20+
*
21+
* This program is distributed in the hope that it will be useful, but
22+
* WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24+
* See the GNU General Public License, version 2.0, for more details.
25+
*
26+
* You should have received a copy of the GNU General Public License
27+
* along with this program; if not, write to the Free Software Foundation, Inc.,
28+
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29+
*/
30+
31+
import { Expr } from '../DevAPI/Expr';
32+
33+
/**
34+
* A JavaScript string to identify the column name while selecting records.
35+
*/
36+
type ProjectedSearchExprStr = string | Expr;
37+
38+
/**
39+
* One or more `ProjectedSearchExprStr` instances.
40+
* As defined by the [`ProjectedSearchExprStrList`](https://dev.mysql.com/doc/x-devapi-userguide/en/crud-ebnf-other-definitions.html#crud-ebnf-projectedsearchexprstrlist)
41+
* EBNF definition.
42+
*/
43+
export type ProjectedSearchExprStrList = ProjectedSearchExprStr | ProjectedSearchExprStr[];

types/lib/DevAPI/Table.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0, as
@@ -29,6 +29,7 @@
2929
*/
3030

3131
import { TableFields } from './Filtering';
32+
import { ProjectedSearchExprStrList } from './Projecting';
3233
import Schema from './Schema';
3334
import TableDelete from './TableDelete';
3435
import TableInsert from './TableInsert';
@@ -77,7 +78,7 @@ interface Table {
7778
* Creates a statement to select rows from the table.
7879
* @returns A fluent statement instance.
7980
*/
80-
select: () => TableSelect
81+
select: (projectedSearchExprStr?: ProjectedSearchExprStrList, ...projectedSearchExprStrList: ProjectedSearchExprStrList[]) => TableSelect
8182
/**
8283
* Creates a statement to update rows in the table.
8384
* @returns A fluent statement instance.

types/test/DevAPI/Table.test-d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0, as
@@ -70,6 +70,18 @@ async function test (): Promise<void> {
7070

7171
// select()
7272
expectType<TableSelect>(table.select());
73+
// using string arguments
74+
expectType<TableSelect>(table.select('foo'));
75+
expectType<TableSelect>(table.select('foo as bar'));
76+
expectType<TableSelect>(table.select('foo', 'bar'));
77+
expectType<TableSelect>(table.select(['foo']));
78+
expectType<TableSelect>(table.select(['foo', 'bar']));
79+
// using Expr arguments
80+
expectType<TableSelect>(table.select(mysqlx.expr('foo')));
81+
expectType<TableSelect>(table.select(mysqlx.expr('foo as bar')));
82+
expectType<TableSelect>(table.select(mysqlx.expr('foo'), mysqlx.expr('bar')));
83+
expectType<TableSelect>(table.select([mysqlx.expr('foo')]));
84+
expectType<TableSelect>(table.select([mysqlx.expr('foo'), mysqlx.expr('bar')]));
7385

7486
// update()
7587
expectType<TableUpdate>(table.update());

0 commit comments

Comments
 (0)