pwi-plata-type 0.4.156 → 0.4.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/@types/sql.d.ts +6 -0
- package/src/tests/sql.test.ts +20 -0
package/package.json
CHANGED
package/src/@types/sql.d.ts
CHANGED
|
@@ -2,10 +2,16 @@ import { Knex } from 'knex'
|
|
|
2
2
|
import moment from 'moment'
|
|
3
3
|
|
|
4
4
|
import "@total-typescript/ts-reset/dist/filter-boolean"
|
|
5
|
+
import { ModelTemplate } from '++/libs/models'
|
|
6
|
+
import { PlataSql } from '..'
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
declare global {
|
|
8
10
|
namespace Sql {
|
|
11
|
+
type SqlGetFunc<const T extends ModelTemplate,const D extends boolean = false> =
|
|
12
|
+
(builder: Sql.Builder<T['template']>, sql: PlataSql.Driver<D>) => PlataPromise<T['type'][]>
|
|
13
|
+
;
|
|
14
|
+
|
|
9
15
|
interface CacheTable {
|
|
10
16
|
coluns: Record<string | number | symbol, Knex.ColumnInfo>
|
|
11
17
|
date: Date
|
package/src/tests/sql.test.ts
CHANGED
|
@@ -40,6 +40,26 @@ describe('PlataSql', () => {
|
|
|
40
40
|
}]
|
|
41
41
|
} as const, {} as const)
|
|
42
42
|
|
|
43
|
+
const testFunc: Sql.SqlGetFunc<typeof modelSql> = async (builder, sql) => {
|
|
44
|
+
const result = await sql.select('TABLE', modelSql).build(
|
|
45
|
+
s => builder(s)
|
|
46
|
+
).toListAsync()
|
|
47
|
+
|
|
48
|
+
if (result.errorID !== undefined) {
|
|
49
|
+
return result
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (result.errors !== undefined) {
|
|
53
|
+
return {
|
|
54
|
+
errorID: '',
|
|
55
|
+
msg: '',
|
|
56
|
+
error: {}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return result.itens
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
const getSqlite3 = () => {
|
|
44
64
|
if (!fs.existsSync(tmpDatabasePath)) {
|
|
45
65
|
fs.copyFileSync(originalDatabasePath, tmpDatabasePath)
|