Skip to content

Commit 2035eda

Browse files
authored
fix: include schema in TVP type declaration (#1730)
1 parent 529402b commit 2035eda

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/data-types/tvp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const TVP: DataType = {
1414

1515
declaration: function(parameter) {
1616
const value = parameter.value as any; // Temporary solution. Remove 'any' later.
17-
return value.name + ' readonly';
17+
const schema = value.schema ? value.schema + '.' : '';
18+
return schema + value.name + ' readonly';
1819
},
1920

2021
generateTypeInfo(parameter) {

test/unit/data-type.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,36 @@ describe('TinyInt', function() {
13841384
});
13851385

13861386
describe('TVP', function() {
1387+
describe('.declaration', function() {
1388+
it('returns type name with readonly', function() {
1389+
const result = TYPES.TVP.declaration({
1390+
value: { name: 'MyTableType', schema: '', columns: [], rows: [] }
1391+
} as any);
1392+
assert.strictEqual(result, 'MyTableType readonly');
1393+
});
1394+
1395+
it('includes schema when present', function() {
1396+
const result = TYPES.TVP.declaration({
1397+
value: { name: 'UDT_StringArray', schema: 'AI', columns: [], rows: [] }
1398+
} as any);
1399+
assert.strictEqual(result, 'AI.UDT_StringArray readonly');
1400+
});
1401+
1402+
it('works with null schema', function() {
1403+
const result = TYPES.TVP.declaration({
1404+
value: { name: 'MyTableType', schema: null, columns: [], rows: [] }
1405+
} as any);
1406+
assert.strictEqual(result, 'MyTableType readonly');
1407+
});
1408+
1409+
it('works with undefined schema', function() {
1410+
const result = TYPES.TVP.declaration({
1411+
value: { name: 'MyTableType', columns: [], rows: [] }
1412+
} as any);
1413+
assert.strictEqual(result, 'MyTableType readonly');
1414+
});
1415+
});
1416+
13871417
describe('.generateParameterLength', function() {
13881418
it('returns the correct data length', function() {
13891419
assert.deepEqual(TYPES.TVP.generateParameterLength({ value: null }, options), Buffer.from([0xFF, 0xFF]));

0 commit comments

Comments
 (0)