You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-11-29 22:27:42 +02:00
153 lines
4.4 KiB
Plaintext
Vendored
153 lines
4.4 KiB
Plaintext
Vendored
---
|
|
sidebar_position: 12
|
|
description: Get records and other functions to work with PostgreSQL in the Open Integration Package, a free open-source integration library for 1C:Enterprise 8, OneScript and CLI
|
|
keywords: [1C, 1С, 1С:Enterprise, 1С:Enterprise 8.3, API, Integration, Services, Exchange, OneScript, CLI, PostgreSQL]
|
|
---
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
|
|
# Get records
|
|
Gets records from the selected table
|
|
|
|
|
|
|
|
`Function GetRecords(Val Table, Val Fields = "*", Val Filters = "", Val Sort = "", Val Count = "", Val Connection = "", Val Tls = "") Export`
|
|
|
|
| Parameter | CLI option | Type | Required | Description |
|
|
|-|-|-|-|-|
|
|
| Table | --table | String | ✔ | Table name |
|
|
| Fields | --fields | Array Of String | ✖ | Fields for selection |
|
|
| Filters | --filter | Array of Structure | ✖ | Filters array. See GetRecordsFilterStrucutre |
|
|
| Sort | --order | Structure Of KeyAndValue | ✖ | Sorting: Key > field name, Value > direction (ASC, DESC) |
|
|
| Count | --limit | Number | ✖ | Limiting the number of received strings |
|
|
| Connection | --dbc | String, Arbitrary | ✖ | Connection or connection string |
|
|
| Tls | --tls | Structure Of KeyAndValue | ✖ | TLS settings, if necessary. See GetTlsSettings |
|
|
|
|
|
|
Returns: Map Of KeyAndValue - Result of query execution
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
|
|
```bsl title="1C:Enterprise/OneScript code example"
|
|
Address = "127.0.0.1";
|
|
Login = "bayselonarrend";
|
|
Password = "12we...";
|
|
Base = "testbase1";
|
|
|
|
ConnectionString = OPI_PostgreSQL.GenerateConnectionString(Address, Base, Login, Password);
|
|
|
|
// All records without filters
|
|
|
|
Table = "testtable";
|
|
|
|
// When using the connection string, a new connection is initialised,
|
|
// which will be closed after the function is executed.
|
|
// If several operations are performed, it is desirable to use one connection,
|
|
// previously created by the CreateConnection function()
|
|
Result = OPI_PostgreSQL.GetRecords(Table, , , , , ConnectionString);
|
|
|
|
// Filter, selected fields, limit and sorting
|
|
|
|
ConnectionString = OPI_PostgreSQL.GenerateConnectionString(Address, "test_data", Login, Password);
|
|
|
|
Table = "test_data";
|
|
|
|
Fields = New Array;
|
|
Fields.Add("first_name");
|
|
Fields.Add("last_name");
|
|
Fields.Add("email");
|
|
|
|
Filters = New Array;
|
|
|
|
FilterStructure1 = New Structure;
|
|
|
|
FilterStructure1.Insert("field", "gender");
|
|
FilterStructure1.Insert("type" , "=");
|
|
FilterStructure1.Insert("value", "Male");
|
|
FilterStructure1.Insert("union", "AND");
|
|
FilterStructure1.Insert("raw" , False);
|
|
|
|
FilterStructure2 = New Structure;
|
|
|
|
FilterStructure2.Insert("field", "id");
|
|
FilterStructure2.Insert("type" , "BETWEEN");
|
|
FilterStructure2.Insert("value", "20 AND 50");
|
|
FilterStructure2.Insert("raw" , True);
|
|
|
|
Filters.Add(FilterStructure1);
|
|
Filters.Add(FilterStructure2);
|
|
|
|
Sort = New Structure("ip_address", "DESC");
|
|
Count = 5;
|
|
|
|
Result = OPI_PostgreSQL.GetRecords(Table, Fields, Filters, Sort, Count, ConnectionString);
|
|
```
|
|
|
|
|
|
<Tabs>
|
|
|
|
<TabItem value="bash" label="Bash" default>
|
|
```bash
|
|
oint postgres GetRecords \
|
|
--table "testtable" \
|
|
--dbc "postgresql://bayselonarrend:***@127.0.0.1:5432/"
|
|
```
|
|
</TabItem>
|
|
|
|
<TabItem value="bat" label="CMD/Bat" default>
|
|
```batch
|
|
oint postgres GetRecords ^
|
|
--table "testtable" ^
|
|
--dbc "postgresql://bayselonarrend:***@127.0.0.1:5432/"
|
|
```
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
|
|
```json title="Result"
|
|
{
|
|
"data": [
|
|
{
|
|
"bigint_field": 9999999,
|
|
"bigserial_field": 9999999,
|
|
"bool_field": true,
|
|
"bytea_field": {
|
|
"BYTEA": "/9j/4VTBRX..."
|
|
},
|
|
"char_field": "A",
|
|
"charn_field": "AAA",
|
|
"date_field": "2025-06-16",
|
|
"dp_field": 1.0002,
|
|
"int_field": 100,
|
|
"ip_field": "127.0.0.1",
|
|
"json_field": {
|
|
"key": "ItsKey",
|
|
"value": 10
|
|
},
|
|
"jsonb_field": {
|
|
"key": "ItsKey",
|
|
"value": 10
|
|
},
|
|
"name_field": "Vitaly",
|
|
"oid_field": 24576,
|
|
"oldchar_field": 1,
|
|
"real_field": 15.1999998092651,
|
|
"serial_field": 100,
|
|
"smallint_field": 5,
|
|
"smallserial_field": 6,
|
|
"text_field": "Some text",
|
|
"time_field": "20:52:18",
|
|
"ts_field": "2025-06-16T20:52:18",
|
|
"tswtz_field": "2025-06-16T18:52:18.280447+03:00",
|
|
"uuid_field": "0cf29094-a9d4-45ce-a133-39392dc2c588",
|
|
"varchar_field": "Some varchar"
|
|
}
|
|
],
|
|
"result": true
|
|
}
|
|
```
|