|
1 | 1 | import duckdb from '@duckdb/node-bindings';
|
2 | 2 | import { expect, suite, test } from 'vitest';
|
| 3 | +import { expectLogicalType } from './utils/expectLogicalType'; |
| 4 | +import { |
| 5 | + BIGINT, |
| 6 | + BLOB, |
| 7 | + BOOLEAN, |
| 8 | + DATE, |
| 9 | + DOUBLE, |
| 10 | + FLOAT, |
| 11 | + HUGEINT, |
| 12 | + INTEGER, |
| 13 | + INTERVAL, |
| 14 | + SMALLINT, |
| 15 | + TIME, |
| 16 | + TIME_TZ, |
| 17 | + TIMESTAMP, |
| 18 | + TINYINT, |
| 19 | + UBIGINT, |
| 20 | + UHUGEINT, |
| 21 | + UINTEGER, |
| 22 | + USMALLINT, |
| 23 | + UTINYINT, |
| 24 | + VARCHAR, |
| 25 | +} from './utils/expectedLogicalTypes'; |
3 | 26 |
|
4 | 27 | suite('values', () => {
|
5 |
| - test('varchar', () => { |
6 |
| - const varchar_text = 'varchar_text'; |
7 |
| - const varchar_value = duckdb.create_varchar(varchar_text); |
| 28 | + test('bool', () => { |
| 29 | + const input = true; |
| 30 | + const bool_value = duckdb.create_bool(input); |
8 | 31 | try {
|
9 |
| - expect(duckdb.get_varchar(varchar_value)).toBe(varchar_text); |
| 32 | + expectLogicalType(duckdb.get_value_type(bool_value), BOOLEAN); |
| 33 | + expect(duckdb.get_bool(bool_value)).toBe(input); |
10 | 34 | } finally {
|
11 |
| - duckdb.destroy_value(varchar_value); |
| 35 | + duckdb.destroy_value(bool_value); |
| 36 | + } |
| 37 | + }); |
| 38 | + test('int8', () => { |
| 39 | + const input = 127; |
| 40 | + const int8_value = duckdb.create_int8(input); |
| 41 | + try { |
| 42 | + expectLogicalType(duckdb.get_value_type(int8_value), TINYINT); |
| 43 | + expect(duckdb.get_int8(int8_value)).toBe(input); |
| 44 | + } finally { |
| 45 | + duckdb.destroy_value(int8_value); |
| 46 | + } |
| 47 | + }); |
| 48 | + test('uint8', () => { |
| 49 | + const input = 255; |
| 50 | + const uint8_value = duckdb.create_uint8(input); |
| 51 | + try { |
| 52 | + expectLogicalType(duckdb.get_value_type(uint8_value), UTINYINT); |
| 53 | + expect(duckdb.get_uint8(uint8_value)).toBe(input); |
| 54 | + } finally { |
| 55 | + duckdb.destroy_value(uint8_value); |
| 56 | + } |
| 57 | + }); |
| 58 | + test('int16', () => { |
| 59 | + const input = 32767; |
| 60 | + const int16_value = duckdb.create_int16(input); |
| 61 | + try { |
| 62 | + expectLogicalType(duckdb.get_value_type(int16_value), SMALLINT); |
| 63 | + expect(duckdb.get_int16(int16_value)).toBe(input); |
| 64 | + } finally { |
| 65 | + duckdb.destroy_value(int16_value); |
| 66 | + } |
| 67 | + }); |
| 68 | + test('uint16', () => { |
| 69 | + const input = 65535; |
| 70 | + const uint16_value = duckdb.create_uint16(input); |
| 71 | + try { |
| 72 | + expectLogicalType(duckdb.get_value_type(uint16_value), USMALLINT); |
| 73 | + expect(duckdb.get_uint16(uint16_value)).toBe(input); |
| 74 | + } finally { |
| 75 | + duckdb.destroy_value(uint16_value); |
| 76 | + } |
| 77 | + }); |
| 78 | + test('int32', () => { |
| 79 | + const input = 2147483647; |
| 80 | + const int32_value = duckdb.create_int32(input); |
| 81 | + try { |
| 82 | + expectLogicalType(duckdb.get_value_type(int32_value), INTEGER); |
| 83 | + expect(duckdb.get_int32(int32_value)).toBe(input); |
| 84 | + } finally { |
| 85 | + duckdb.destroy_value(int32_value); |
| 86 | + } |
| 87 | + }); |
| 88 | + test('uint32', () => { |
| 89 | + const input = 4294967295; |
| 90 | + const uint32_value = duckdb.create_uint32(input); |
| 91 | + try { |
| 92 | + expectLogicalType(duckdb.get_value_type(uint32_value), UINTEGER); |
| 93 | + expect(duckdb.get_uint32(uint32_value)).toBe(input); |
| 94 | + } finally { |
| 95 | + duckdb.destroy_value(uint32_value); |
12 | 96 | }
|
13 | 97 | });
|
14 | 98 | test('int64', () => {
|
15 |
| - const int64_bigint = 12345n; |
16 |
| - const int64_value = duckdb.create_int64(int64_bigint); |
| 99 | + const input = 9223372036854775807n; |
| 100 | + const int64_value = duckdb.create_int64(input); |
17 | 101 | try {
|
18 |
| - expect(duckdb.get_int64(int64_value)).toBe(int64_bigint); |
| 102 | + expectLogicalType(duckdb.get_value_type(int64_value), BIGINT); |
| 103 | + expect(duckdb.get_int64(int64_value)).toBe(input); |
19 | 104 | } finally {
|
20 | 105 | duckdb.destroy_value(int64_value);
|
21 | 106 | }
|
22 | 107 | });
|
| 108 | + test('uint64', () => { |
| 109 | + const input = 18446744073709551615n; |
| 110 | + const uint64_value = duckdb.create_uint64(input); |
| 111 | + try { |
| 112 | + expectLogicalType(duckdb.get_value_type(uint64_value), UBIGINT); |
| 113 | + expect(duckdb.get_uint64(uint64_value)).toBe(input); |
| 114 | + } finally { |
| 115 | + duckdb.destroy_value(uint64_value); |
| 116 | + } |
| 117 | + }); |
| 118 | + test('hugeint', () => { |
| 119 | + const input = 170141183460469231731687303715884105727n; |
| 120 | + const hugeint_value = duckdb.create_hugeint(input); |
| 121 | + try { |
| 122 | + expectLogicalType(duckdb.get_value_type(hugeint_value), HUGEINT); |
| 123 | + expect(duckdb.get_hugeint(hugeint_value)).toBe(input); |
| 124 | + } finally { |
| 125 | + duckdb.destroy_value(hugeint_value); |
| 126 | + } |
| 127 | + }); |
| 128 | + test('uhugeint', () => { |
| 129 | + const input = 340282366920938463463374607431768211455n; |
| 130 | + const uhugeint_value = duckdb.create_uhugeint(input); |
| 131 | + try { |
| 132 | + expectLogicalType(duckdb.get_value_type(uhugeint_value), UHUGEINT); |
| 133 | + expect(duckdb.get_uhugeint(uhugeint_value)).toBe(input); |
| 134 | + } finally { |
| 135 | + duckdb.destroy_value(uhugeint_value); |
| 136 | + } |
| 137 | + }); |
| 138 | + test('float', () => { |
| 139 | + const input = 3.4028234663852886e+38; |
| 140 | + const float_value = duckdb.create_float(input); |
| 141 | + try { |
| 142 | + expectLogicalType(duckdb.get_value_type(float_value), FLOAT); |
| 143 | + expect(duckdb.get_float(float_value)).toBe(input); |
| 144 | + } finally { |
| 145 | + duckdb.destroy_value(float_value); |
| 146 | + } |
| 147 | + }); |
| 148 | + test('double', () => { |
| 149 | + const input = 1.7976931348623157e+308; |
| 150 | + const double_value = duckdb.create_double(input); |
| 151 | + try { |
| 152 | + expectLogicalType(duckdb.get_value_type(double_value), DOUBLE); |
| 153 | + expect(duckdb.get_double(double_value)).toBe(input); |
| 154 | + } finally { |
| 155 | + duckdb.destroy_value(double_value); |
| 156 | + } |
| 157 | + }); |
| 158 | + test('date', () => { |
| 159 | + const input = { days: 2147483646 }; |
| 160 | + const date_value = duckdb.create_date(input); |
| 161 | + try { |
| 162 | + expectLogicalType(duckdb.get_value_type(date_value), DATE); |
| 163 | + expect(duckdb.get_date(date_value)).toStrictEqual(input); |
| 164 | + } finally { |
| 165 | + duckdb.destroy_value(date_value); |
| 166 | + } |
| 167 | + }); |
| 168 | + test('time', () => { |
| 169 | + const input = { micros: 86400000000 }; |
| 170 | + const time_value = duckdb.create_time(input); |
| 171 | + try { |
| 172 | + expectLogicalType(duckdb.get_value_type(time_value), TIME); |
| 173 | + expect(duckdb.get_time(time_value)).toStrictEqual(input); |
| 174 | + } finally { |
| 175 | + duckdb.destroy_value(time_value); |
| 176 | + } |
| 177 | + }); |
| 178 | + test('time_tz', () => { |
| 179 | + const input = { bits: 1449551462400115198n }; |
| 180 | + const time_tz_value = duckdb.create_time_tz_value(input); |
| 181 | + try { |
| 182 | + expectLogicalType(duckdb.get_value_type(time_tz_value), TIME_TZ); |
| 183 | + expect(duckdb.get_time_tz(time_tz_value)).toStrictEqual(input); |
| 184 | + } finally { |
| 185 | + duckdb.destroy_value(time_tz_value); |
| 186 | + } |
| 187 | + }); |
| 188 | + test('timestamp', () => { |
| 189 | + const input = { micros: 9223372036854775806n }; |
| 190 | + const timestamp_value = duckdb.create_timestamp(input); |
| 191 | + try { |
| 192 | + expectLogicalType(duckdb.get_value_type(timestamp_value), TIMESTAMP); |
| 193 | + expect(duckdb.get_timestamp(timestamp_value)).toStrictEqual(input); |
| 194 | + } finally { |
| 195 | + duckdb.destroy_value(timestamp_value); |
| 196 | + } |
| 197 | + }); |
| 198 | + test('interval', () => { |
| 199 | + const input = { months: 999, days: 999, micros: 999999999n }; |
| 200 | + const interval_value = duckdb.create_interval(input); |
| 201 | + try { |
| 202 | + expectLogicalType(duckdb.get_value_type(interval_value), INTERVAL); |
| 203 | + expect(duckdb.get_interval(interval_value)).toStrictEqual(input); |
| 204 | + } finally { |
| 205 | + duckdb.destroy_value(interval_value); |
| 206 | + } |
| 207 | + }); |
| 208 | + test('blob', () => { |
| 209 | + const input = Buffer.from('thisisalongblob\x00withnullbytes'); |
| 210 | + const blob_value = duckdb.create_blob(input); |
| 211 | + try { |
| 212 | + expectLogicalType(duckdb.get_value_type(blob_value), BLOB); |
| 213 | + expect(duckdb.get_blob(blob_value)).toStrictEqual(input); |
| 214 | + } finally { |
| 215 | + duckdb.destroy_value(blob_value); |
| 216 | + } |
| 217 | + }); |
| 218 | + test('varchar', () => { |
| 219 | + const input = 'varchar_text'; |
| 220 | + const varchar_value = duckdb.create_varchar(input); |
| 221 | + try { |
| 222 | + expectLogicalType(duckdb.get_value_type(varchar_value), VARCHAR); |
| 223 | + expect(duckdb.get_varchar(varchar_value)).toBe(input); |
| 224 | + } finally { |
| 225 | + duckdb.destroy_value(varchar_value); |
| 226 | + } |
| 227 | + }); |
23 | 228 | });
|
0 commit comments