| 1 | // Copyright 2023 LanceDB Developers. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | import { toSQL } from '../util' |
| 16 | import * as chai from 'chai' |
| 17 | |
| 18 | const expect = chai.expect |
| 19 | |
| 20 | describe('toSQL', function () { |
| 21 | it('should turn string to SQL expression', function () { |
| 22 | expect(toSQL('foo')).to.equal("'foo'") |
| 23 | }) |
| 24 | |
| 25 | it('should turn number to SQL expression', function () { |
| 26 | expect(toSQL(123)).to.equal('123') |
| 27 | }) |
| 28 | |
| 29 | it('should turn boolean to SQL expression', function () { |
| 30 | expect(toSQL(true)).to.equal('TRUE') |
| 31 | }) |
| 32 | |
| 33 | it('should turn null to SQL expression', function () { |
| 34 | expect(toSQL(null)).to.equal('NULL') |
| 35 | }) |
| 36 | |
| 37 | it('should turn Date to SQL expression', function () { |
| 38 | const date = new Date('05 October 2011 14:48 UTC') |
| 39 | expect(toSQL(date)).to.equal("'2011-10-05T14:48:00.000Z'") |
| 40 | }) |
| 41 | |
| 42 | it('should turn array to SQL expression', function () { |
| 43 | expect(toSQL(['foo', 'bar', true, 1])).to.equal("['foo', 'bar', TRUE, 1]") |
| 44 | }) |
| 45 | }) |