@oino-ts/db-postgresql 0.0.11 → 0.0.12
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/README.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Register database and logger
|
|
25
|
-
Register your database implementation and logger (see [`OINOConsoleLog`](https://pragmatta.github.io/oino-ts/classes/
|
|
25
|
+
Register your database implementation and logger (see [`OINOConsoleLog`](https://pragmatta.github.io/oino-ts/classes/types_src.OINOConsoleLog.html) how to implement your own)
|
|
26
26
|
|
|
27
27
|
```
|
|
28
28
|
OINOLog.setLogger(new OINOConsoleLog())
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
### Create a database
|
|
33
|
-
Creating a database connection [`OINODb`](https://pragmatta.github.io/oino-ts/classes/
|
|
33
|
+
Creating a database connection [`OINODb`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODb.html) is done by passing [`OINODbParams`](https://pragmatta.github.io/oino-ts/types/db_src.OINODbParams.html) to the factory method. For [`OINODbBunSqlite`](https://pragmatta.github.io/oino-ts/classes/db_bunsqlite_src.OINODbBunSqlite.html) that means a file url for the database file, for others network host, port, credentials etc.
|
|
34
34
|
```
|
|
35
35
|
const db:OINODb = await OINOFactory.createDb( { type: "OINODbBunSqlite", url: "file://../localDb/northwind.sqlite" } )
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### Create an API
|
|
39
|
-
From a database you can create an [`OINOApi`](https://pragmatta.github.io/oino-ts/classes/
|
|
39
|
+
From a database you can create an [`OINOApi`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbApi.html) by passing [`OINOApiParams`](https://pragmatta.github.io/oino-ts/types/db_src.OINODbApiParams.html) with table name and preferences to the factory method.
|
|
40
40
|
```
|
|
41
41
|
const api_employees:OINOApi = await OINOFactory.createApi(db, { tableName: "Employees", excludeFields:["BirthDate"] })
|
|
42
42
|
```
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
### Write results back to HTTP Response
|
|
52
|
-
The results for a GET request will contain [`OINOModelSet`](https://pragmatta.github.io/oino-ts/classes/
|
|
52
|
+
The results for a GET request will contain [`OINOModelSet`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbModelSet.html) data that can be written out as JSON or CSV as needed. For other requests result is just success or error with messages.
|
|
53
53
|
```
|
|
54
54
|
return new Response(result.modelset.writeString(OINOContentType.json))
|
|
55
55
|
```
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
To support tables with multipart primary keys OINO generates a composite key `_OINOID_` that is included in the result and can be used as the REST ID. For example in the example above table `OrderDetails` has two primary keys `OrderID` and `ProductID` making the `_OINOID_` of form `11077:99`.
|
|
135
135
|
|
|
136
136
|
## Power Of SQL
|
|
137
|
-
Since OINO controls the SQL, WHERE-conditions can be defined with [`OINOSqlFilter`](https://pragmatta.github.io/oino-ts/classes/
|
|
137
|
+
Since OINO controls the SQL, WHERE-conditions can be defined with [`OINOSqlFilter`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbSqlFilter.html) and order with [`OINOSqlOrder`](https://pragmatta.github.io/oino-ts/classes/db_src.OINODbSqlOrder.html) that are passed as HTTP request parameters. No more API development where you make unique API endpoints for each filter that fetch all data with original API and filter in backend code. Every API can be filtered when and as needed without unnessecary data tranfer and utilizing SQL indexing when available.
|
|
138
138
|
|
|
139
139
|
## Swagger Support
|
|
140
140
|
Swagger is great as long as the definitions are updated and with OINO you can automatically get a Swagger definition including a data model schema.
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
OINO is developped Typescript first but compiles to standard CommonJS and the NPM packages should work on either ESM / CommonJS. Checkout sample apps `readmeApp` (ESM) and `nodeApp` (CommonJS).
|
|
150
150
|
|
|
151
151
|
## HTMX support
|
|
152
|
-
OINO is [htmx.org](https://htmx.org) friendly, allowing easy translation of [`OINODataRow`](https://pragmatta.github.io/oino-ts/types/
|
|
152
|
+
OINO is [htmx.org](https://htmx.org) friendly, allowing easy translation of [`OINODataRow`](https://pragmatta.github.io/oino-ts/types/db_src.OINODataRow.html) to HTML output using templates (cf. the [htmx sample app](https://github.com/pragmatta/oino-ts/tree/main/samples/htmxApp)).
|
|
153
153
|
|
|
154
154
|
### Hashids
|
|
155
155
|
Autoinc numeric id's are very pragmatic and fit well with OINO (e.g. using a form without primary key fields to insert new rows with database assigned ids). However it's not always sensible to share information about the sequence. Hashids solve this by masking the original values by encrypting the ids using AES-128 and some randomness. Length of the hashid can be chosen from 12-32 characters where longer ids provide more security. However this should not be considereded a cryptographic solution for keeping ids secret but rather making it infeasible to iterate all ids.
|
|
@@ -171,7 +171,15 @@ WHERE table_name = `;
|
|
|
171
171
|
return cellValue.toString();
|
|
172
172
|
}
|
|
173
173
|
else if (sqlType == "bytea") {
|
|
174
|
-
|
|
174
|
+
if (cellValue instanceof Buffer) {
|
|
175
|
+
return "'\\x" + cellValue.toString("hex") + "'";
|
|
176
|
+
}
|
|
177
|
+
else if (cellValue instanceof Uint8Array) {
|
|
178
|
+
return "'\\x" + Buffer.from(cellValue).toString("hex") + "'";
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return "\'" + cellValue?.toString() + "\'";
|
|
182
|
+
}
|
|
175
183
|
}
|
|
176
184
|
else if (sqlType == "boolean") {
|
|
177
185
|
if (cellValue == null || cellValue == "" || cellValue.toString().toLowerCase() == "false" || cellValue == "0") {
|
|
@@ -168,7 +168,15 @@ WHERE table_name = `;
|
|
|
168
168
|
return cellValue.toString();
|
|
169
169
|
}
|
|
170
170
|
else if (sqlType == "bytea") {
|
|
171
|
-
|
|
171
|
+
if (cellValue instanceof Buffer) {
|
|
172
|
+
return "'\\x" + cellValue.toString("hex") + "'";
|
|
173
|
+
}
|
|
174
|
+
else if (cellValue instanceof Uint8Array) {
|
|
175
|
+
return "'\\x" + Buffer.from(cellValue).toString("hex") + "'";
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return "\'" + cellValue?.toString() + "\'";
|
|
179
|
+
}
|
|
172
180
|
}
|
|
173
181
|
else if (sqlType == "boolean") {
|
|
174
182
|
if (cellValue == null || cellValue == "" || cellValue.toString().toLowerCase() == "false" || cellValue == "0") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oino-ts/db-postgresql",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "OINO TS package for using Postgresql databases.",
|
|
5
5
|
"author": "Matias Kiviniemi (pragmatta)",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"module": "./dist/esm/index.js",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@oino-ts/db": "^0.0.
|
|
23
|
+
"@oino-ts/db": "^0.0.12",
|
|
24
24
|
"pg": "^8.11.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
package/src/OINODbPostgresql.ts
CHANGED
|
@@ -186,7 +186,13 @@ WHERE table_name = `
|
|
|
186
186
|
return cellValue.toString()
|
|
187
187
|
|
|
188
188
|
} else if (sqlType == "bytea") {
|
|
189
|
-
|
|
189
|
+
if (cellValue instanceof Buffer) {
|
|
190
|
+
return "'\\x" + (cellValue as Buffer).toString("hex") + "'"
|
|
191
|
+
} else if (cellValue instanceof Uint8Array) {
|
|
192
|
+
return "'\\x" + Buffer.from(cellValue as Uint8Array).toString("hex") + "'"
|
|
193
|
+
} else {
|
|
194
|
+
return "\'" + cellValue?.toString() + "\'"
|
|
195
|
+
}
|
|
190
196
|
|
|
191
197
|
} else if (sqlType == "boolean") {
|
|
192
198
|
if (cellValue == null || cellValue == "" || cellValue.toString().toLowerCase() == "false" || cellValue == "0") {
|