Skip to content

Commit

Permalink
Merge pull request #395 from ydb-platform/Add-DECLARE
Browse files Browse the repository at this point in the history
fix: add DECLARE that is still required by YDB 24.1
  • Loading branch information
Zork33 committed Jul 4, 2024
2 parents 63efa94 + 8920fee commit 149d5dc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
16 changes: 16 additions & 0 deletions examples/basic-example-v2-with-query-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ async function selectWithParameters(driver: Driver, data: ThreeIds[], logger: Lo
'$episodeId': episode.getTypedValue('episodeId')
},
text: `
DECLARE $seriesId AS Uint64;
DECLARE $seasonId AS Uint64;
DECLARE $episodeId AS Uint64;
SELECT title,
air_date
FROM episodes
Expand Down Expand Up @@ -173,6 +177,10 @@ async function explicitTcl(driver: Driver, ids: ThreeIds, logger: Logger) {
'$episodeId': episode.getTypedValue('episodeId')
},
text: `
DECLARE $seriesId AS Uint64;
DECLARE $seasonId AS Uint64;
DECLARE $episodeId AS Uint64;
UPDATE episodes
SET air_date = CurrentUtcDate()
WHERE series_id = $seriesId
Expand Down Expand Up @@ -200,6 +208,10 @@ async function transactionPerWholeDo(driver: Driver, ids: ThreeIds, logger: Logg
'$episodeId': episode.getTypedValue('episodeId')
},
text: `
DECLARE $seriesId AS Uint64;
DECLARE $seasonId AS Uint64;
DECLARE $episodeId AS Uint64;
UPDATE episodes
SET air_date = CurrentUtcDate()
WHERE series_id = $seriesId
Expand All @@ -221,6 +233,10 @@ async function fillTablesWithData(driver: Driver, _logger: Logger) {
'$episodesData': getEpisodesData()
},
text: `
DECLARE $seriesData AS List<Struct<series_id: Uint64, title: Utf8, release_date: Date, series_info: Utf8>>;
DECLARE $seasonsData AS List<Struct<series_id: Uint64, season_id: Uint64, title: Utf8, first_aired: Date, last_aired: Date>>;
DECLARE $episodesData AS List<Struct<series_id: Uint64, season_id: Uint64, episode_id: Uint64, title: Utf8, air_date: Date>>;
REPLACE
INTO
${SERIES_TABLE}
Expand Down
11 changes: 9 additions & 2 deletions src/__tests__/e2e/query-service/method-execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ describe('Query.execute()', () => {

await session.execute({
text: `
DECLARE $table AS List<Struct<id: Uint64, title: Utf8, time: Datetime,>>;
UPSERT INTO ${TABLE_NAME} (id, title, time)
SELECT id, title, time FROM AS_TABLE($table)
SELECT id, title, time FROM AS_TABLE($table);
`,
parameters: {
'$table': Row.asTypedCollection([...dataGenerator(generatedRowsCount)]),
Expand Down Expand Up @@ -196,9 +197,15 @@ describe('Query.execute()', () => {
'$title1': TypedValues.text('Some title1'),
'$id2': TypedValues.uint64(2),
'$title2': TypedValues.text('Some title2'),
'$timestamp': TypedValues.timestamp(new Date()),
'$timestamp': TypedValues.datetime(new Date()),
},
text: `
DECLARE $id1 AS Uint64;
DECLARE $title1 AS Utf8;
DECLARE $id2 AS Uint64;
DECLARE $title2 AS Utf8;
DECLARE $timestamp AS Datetime;
INSERT INTO ${TABLE_NAME} (id, title, time)
VALUES ($id1, $title1, $timestamp);
INSERT INTO ${TABLE_NAME} (id, title, time)
Expand Down
8 changes: 7 additions & 1 deletion src/__tests__/e2e/query-service/rows-conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,15 @@ describe('Rows conversion', () => {
'$title1': TypedValues.text('Some title1'),
'$id2': TypedValues.uint64(2),
'$title2': TypedValues.text('Some title2'),
'$timestamp': TypedValues.timestamp(new Date()),
'$timestamp': TypedValues.datetime(new Date()),
},
text: `
DECLARE $id1 AS Uint64;
DECLARE $title1 AS Utf8;
DECLARE $id2 AS Uint64;
DECLARE $title2 AS Utf8;
DECLARE $timestamp AS Datetime;
INSERT INTO ${TABLE_NAME} (id, row_title, time)
VALUES ($id1, $title1, $timestamp);
INSERT INTO ${TABLE_NAME} (id, row_title, time)
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/e2e/table-service/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Types', () => {

describe('Convert from native to YDB value', () => {
describe('Primitive values', () => {
it.only('Numeric values', () => {
it('Numeric values', () => {
expect(TypedValues.bool(true)).toEqual({
type: {typeId: Ydb.Type.PrimitiveTypeId.BOOL},
value: {boolValue: true},
Expand Down

0 comments on commit 149d5dc

Please sign in to comment.