-
-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(types): add missing types to TypeCast (#2390)
* fix(types): add missing types to TypeCast * chore: add comment on typeCast for execute * ci: create strict tests for typeCast option
- Loading branch information
1 parent
8dd11b2
commit 78ce495
Showing
4 changed files
with
281 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { QueryOptions, ConnectionOptions } from '../../../index.js'; | ||
import { | ||
QueryOptions as QueryOptionsP, | ||
ConnectionOptions as ConnectionOptionsP, | ||
} from '../../../promise.js'; | ||
import { access, sql } from '../promise/baseConnection.js'; | ||
|
||
// Callback: QueryOptions | ||
{ | ||
const options1: QueryOptions = { | ||
sql, | ||
typeCast: true, | ||
}; | ||
|
||
const options2: QueryOptions = { | ||
sql, | ||
typeCast: false, | ||
}; | ||
|
||
const options3: QueryOptions = { | ||
sql, | ||
typeCast: (field, next) => { | ||
const db: string = field.db; | ||
const length: number = field.length; | ||
const name: string = field.name; | ||
const table: string = field.table; | ||
const type: string = field.type; | ||
const buffer: Buffer | null = field.buffer(); | ||
const string: string | null = field.string(); | ||
const geometry: | ||
| { x: number; y: number } | ||
| { x: number; y: number }[] | ||
| null = field.geometry(); | ||
|
||
console.log(db, length, name, table, type); | ||
console.log(buffer, string, geometry); | ||
|
||
return next(); | ||
}, | ||
}; | ||
|
||
console.log(options1, options2, options3); | ||
} | ||
|
||
// Callback: ConnectionOptions | ||
{ | ||
const options1: ConnectionOptions = { | ||
...access, | ||
typeCast: true, | ||
}; | ||
|
||
const options2: ConnectionOptions = { | ||
...access, | ||
typeCast: false, | ||
}; | ||
|
||
const options3: ConnectionOptions = { | ||
...access, | ||
typeCast: (field, next) => { | ||
const db: string = field.db; | ||
const length: number = field.length; | ||
const name: string = field.name; | ||
const table: string = field.table; | ||
const type: string = field.type; | ||
const buffer: Buffer | null = field.buffer(); | ||
const string: string | null = field.string(); | ||
const geometry: | ||
| { x: number; y: number } | ||
| { x: number; y: number }[] | ||
| null = field.geometry(); | ||
|
||
console.log(db, length, name, table, type); | ||
console.log(buffer, string, geometry); | ||
|
||
return next(); | ||
}, | ||
}; | ||
|
||
console.log(options1, options2, options3); | ||
} | ||
|
||
// Promise: QueryOptions | ||
{ | ||
const options1: QueryOptionsP = { | ||
sql, | ||
typeCast: true, | ||
}; | ||
|
||
const options2: QueryOptionsP = { | ||
sql, | ||
typeCast: false, | ||
}; | ||
|
||
const options3: QueryOptionsP = { | ||
sql, | ||
typeCast: (field, next) => { | ||
const db: string = field.db; | ||
const length: number = field.length; | ||
const name: string = field.name; | ||
const table: string = field.table; | ||
const type: string = field.type; | ||
const buffer: Buffer | null = field.buffer(); | ||
const string: string | null = field.string(); | ||
const geometry: | ||
| { x: number; y: number } | ||
| { x: number; y: number }[] | ||
| null = field.geometry(); | ||
|
||
console.log(db, length, name, table, type); | ||
console.log(buffer, string, geometry); | ||
|
||
return next(); | ||
}, | ||
}; | ||
|
||
console.log(options1, options2, options3); | ||
} | ||
|
||
// Promise: ConnectionOptions | ||
{ | ||
const options1: ConnectionOptionsP = { | ||
...access, | ||
typeCast: true, | ||
}; | ||
|
||
const options2: ConnectionOptionsP = { | ||
...access, | ||
typeCast: false, | ||
}; | ||
|
||
const options3: ConnectionOptionsP = { | ||
...access, | ||
typeCast: (field, next) => { | ||
const db: string = field.db; | ||
const length: number = field.length; | ||
const name: string = field.name; | ||
const table: string = field.table; | ||
const type: string = field.type; | ||
const buffer: Buffer | null = field.buffer(); | ||
const string: string | null = field.string(); | ||
const geometry: | ||
| { x: number; y: number } | ||
| { x: number; y: number }[] | ||
| null = field.geometry(); | ||
|
||
console.log(db, length, name, table, type); | ||
console.log(buffer, string, geometry); | ||
|
||
return next(); | ||
}, | ||
}; | ||
|
||
console.log(options1, options2, options3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
type Geometry = { | ||
x: number; | ||
y: number; | ||
}; | ||
|
||
type Type = { | ||
type: | ||
| 'DECIMAL' | ||
| 'TINY' | ||
| 'SHORT' | ||
| 'LONG' | ||
| 'FLOAT' | ||
| 'DOUBLE' | ||
| 'NULL' | ||
| 'TIMESTAMP' | ||
| 'TIMESTAMP2' | ||
| 'LONGLONG' | ||
| 'INT24' | ||
| 'DATE' | ||
| 'TIME' | ||
| 'TIME2' | ||
| 'DATETIME' | ||
| 'DATETIME2' | ||
| 'YEAR' | ||
| 'NEWDATE' | ||
| 'VARCHAR' | ||
| 'BIT' | ||
| 'JSON' | ||
| 'NEWDECIMAL' | ||
| 'ENUM' | ||
| 'SET' | ||
| 'TINY_BLOB' | ||
| 'MEDIUM_BLOB' | ||
| 'LONG_BLOB' | ||
| 'BLOB' | ||
| 'VAR_STRING' | ||
| 'STRING' | ||
| 'GEOMETRY'; | ||
}; | ||
|
||
type Field = Type & { | ||
length: number; | ||
db: string; | ||
table: string; | ||
name: string; | ||
string: () => string | null; | ||
buffer: () => Buffer | null; | ||
geometry: () => Geometry | Geometry[] | null; | ||
}; | ||
|
||
type Next = () => void; | ||
|
||
export type TypeCast = ((field: Field, next: Next) => any) | boolean; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters