You've already forked OpenIntegrations
mirror of
https://github.com/Bayselonarrend/OpenIntegrations.git
synced 2025-11-25 22:12:29 +02:00
129 lines
7.8 KiB
Plaintext
Vendored
129 lines
7.8 KiB
Plaintext
Vendored
---
|
|
sidebar_position: 11
|
|
description: Add rows 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';
|
|
|
|
# Add rows
|
|
Adds new rows to the table
|
|
|
|
|
|
|
|
`Function AddRecords(Val Table, Val DataArray, Val Transaction = True, Val Connection = "", Val Tls = "") Export`
|
|
|
|
| Parameter | CLI option | Type | Required | Description |
|
|
|-|-|-|-|-|
|
|
| Table | --table | String | ✔ | Table name |
|
|
| DataArray | --rows | Array of Structure | ✔ | An array of string data structures: Key > field, Value > field value |
|
|
| Transaction | --trn | Boolean | ✖ | True > adding records to transactions with rollback on error |
|
|
| 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/>
|
|
|
|
:::tip
|
|
Record data is specified as an array of structures of the following type:<br/>`{'Field name 1': {'Type': 'Value'}, 'Field name 2': {'Type': 'Value'},...}`
|
|
|
|
The list of available types is described on the initial page of the PostgreSQL library documentation
|
|
:::
|
|
<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);
|
|
|
|
Table = "testtable";
|
|
RecordsArray = New Array;
|
|
|
|
Image = "https://hut.openintegrations.dev/test_data/picture.jpg";
|
|
OPI_TypeConversion.GetBinaryData(Image); // Image - Type: BinaryData
|
|
|
|
CasualStructure = New Structure("key,value", "ItsKey", 10);
|
|
|
|
CurrentDate = OPI_Tools.GetCurrentDate();
|
|
CurrentDateTZ = OPI_Tools.DateRFC3339(CurrentDate, "+05:00");
|
|
|
|
RecordStructure = New Structure;
|
|
RecordStructure.Insert("bool_field" , New Structure("BOOL" , True));
|
|
RecordStructure.Insert("oldchar_field" , New Structure("OLDCHAR" , 1)); // or "char"
|
|
RecordStructure.Insert("smallint_field" , New Structure("SMALLINT" , 5));
|
|
RecordStructure.Insert("smallserial_field", New Structure("SMALLSERIAL" , 6));
|
|
RecordStructure.Insert("int_field" , New Structure("INT" , 100));
|
|
RecordStructure.Insert("serial_field" , New Structure("SERIAL" , 100));
|
|
RecordStructure.Insert("oid_field" , New Structure("OID" , 24576));
|
|
RecordStructure.Insert("bigint_field" , New Structure("BIGINT" , 9999999));
|
|
RecordStructure.Insert("bigserial_field" , New Structure("BIGSERIAL" , 9999999));
|
|
RecordStructure.Insert("real_field" , New Structure("REAL" , 15.2));
|
|
RecordStructure.Insert("dp_field" , New Structure("DOUBLE_PRECISION" , 1.0002)); // or DOUBLE PRECISION
|
|
RecordStructure.Insert("text_field" , New Structure("TEXT" , "Some text"));
|
|
RecordStructure.Insert("varchar_field" , New Structure("VARCHAR" , "Some varchar"));
|
|
RecordStructure.Insert("charn_field" , New Structure("CHAR" , "AAA"));
|
|
RecordStructure.Insert("char_field" , New Structure("CHAR" , "A"));
|
|
RecordStructure.Insert("name_field" , New Structure("NAME" , "Vitaly"));
|
|
RecordStructure.Insert("bytea_field" , New Structure("BYTEA" , Image));
|
|
RecordStructure.Insert("ts_field" , New Structure("TIMESTAMP" , CurrentDate));
|
|
RecordStructure.Insert("tswtz_field" , New Structure("TIMESTAMP_WITH_TIME_ZONE", CurrentDateTZ)); // or TIMESTAMP WITH TIME ZONE
|
|
RecordStructure.Insert("ip_field" , New Structure("INET" , "127.0.0.1"));
|
|
RecordStructure.Insert("json_field" , New Structure("JSON" , CasualStructure));
|
|
RecordStructure.Insert("jsonb_field" , New Structure("JSONB" , CasualStructure));
|
|
RecordStructure.Insert("date_field" , New Structure("DATE" , CurrentDate));
|
|
RecordStructure.Insert("time_field" , New Structure("TIME" , CurrentDate));
|
|
RecordStructure.Insert("uuid_field" , New Structure("UUID" , New UUID));
|
|
|
|
RecordsArray.Add(RecordStructure);
|
|
|
|
// 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.AddRecords(Table, RecordsArray, True, ConnectionString);
|
|
```
|
|
|
|
|
|
<Tabs>
|
|
|
|
<TabItem value="bash" label="Bash" default>
|
|
```bash
|
|
oint postgres AddRecords \
|
|
--table "testtable" \
|
|
--rows "[{'bool_field':{'BOOL':true},'oldchar_field':{'OLDCHAR':1},'smallint_field':{'SMALLINT':5},'smallserial_field':{'SMALLSERIAL':6},'int_field':{'INT':100},'serial_field':{'SERIAL':100},'oid_field':{'OID':24576},'bigint_field':{'BIGINT':9999999},'bigserial_field':{'BIGSERIAL':9999999},'real_field':{'REAL':15.2},'dp_field':{'DOUBLE_PRECISION':1.0002},'text_field':{'TEXT':'Some text'},'varchar_field':{'VARCHAR':'Some varchar'},'charn_field':{'CHAR':'AAA'},'char_field':{'CHAR':'A'},'name_field':{'NAME':'Vitaly'},'bytea_field':{'BYTEA':'C:\\Users\\Administrator\\AppData\\Local\\Temp\\ullcaqayfkv.tmp'},'ts_field':{'TIMESTAMP':'2025-06-18T20:14:21.0341888Z'},'tswtz_field':{'TIMESTAMP_WITH_TIME_ZONE':'2025-06-18T20:14:21.0341888+05:00'},'ip_field':{'INET':'127.0.0.1'},'json_field':{'JSON':{'key':'***','value':10}},'jsonb_field':{'JSONB':{'key':'***','value':10}},'date_field':{'DATE':'2025-06-18T20:14:21.0341888Z'},'time_field':{'TIME':'2025-06-18T20:14:21.0341888Z'},'uuid_field':{'UUID':'9858def8-3d48-4c74-a89c-589857836f3e'}}]" \
|
|
--trn true \
|
|
--dbc "postgresql://bayselonarrend:***@127.0.0.1:5432/"
|
|
```
|
|
</TabItem>
|
|
|
|
<TabItem value="bat" label="CMD/Bat" default>
|
|
```batch
|
|
oint postgres AddRecords ^
|
|
--table "testtable" ^
|
|
--rows "[{'bool_field':{'BOOL':true},'oldchar_field':{'OLDCHAR':1},'smallint_field':{'SMALLINT':5},'smallserial_field':{'SMALLSERIAL':6},'int_field':{'INT':100},'serial_field':{'SERIAL':100},'oid_field':{'OID':24576},'bigint_field':{'BIGINT':9999999},'bigserial_field':{'BIGSERIAL':9999999},'real_field':{'REAL':15.2},'dp_field':{'DOUBLE_PRECISION':1.0002},'text_field':{'TEXT':'Some text'},'varchar_field':{'VARCHAR':'Some varchar'},'charn_field':{'CHAR':'AAA'},'char_field':{'CHAR':'A'},'name_field':{'NAME':'Vitaly'},'bytea_field':{'BYTEA':'C:\\Users\\Administrator\\AppData\\Local\\Temp\\ullcaqayfkv.tmp'},'ts_field':{'TIMESTAMP':'2025-06-18T20:14:21.0341888Z'},'tswtz_field':{'TIMESTAMP_WITH_TIME_ZONE':'2025-06-18T20:14:21.0341888+05:00'},'ip_field':{'INET':'127.0.0.1'},'json_field':{'JSON':{'key':'***','value':10}},'jsonb_field':{'JSONB':{'key':'***','value':10}},'date_field':{'DATE':'2025-06-18T20:14:21.0341888Z'},'time_field':{'TIME':'2025-06-18T20:14:21.0341888Z'},'uuid_field':{'UUID':'9858def8-3d48-4c74-a89c-589857836f3e'}}]" ^
|
|
--trn true ^
|
|
--dbc "postgresql://bayselonarrend:***@127.0.0.1:5432/"
|
|
```
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
|
|
```json title="Result"
|
|
{
|
|
"commit": {
|
|
"result": true
|
|
},
|
|
"result": true,
|
|
"rows": 1,
|
|
"errors": []
|
|
}
|
|
```
|