1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-04-02 22:05:37 +02:00
OpenIntegrations/docs/en/md/SQLite/Orm/Add-records.mdx
Vitaly the Alpaca (bot) 296e5c5dd8 Main build (Jenkins)
2025-01-12 19:10:21 +03:00

101 lines
3.6 KiB
Plaintext
Vendored

---
sidebar_position: 3
---
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 = "") 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 | --db | String, Arbitrary | ✖ | Existing connection or database path |
Returns: Structure Of KeyAndValue, String - Result of query execution
<br/>
:::tip
Binary data can also be transferred as a structure `{'blob':File path}`
:::
<br/>
```bsl title="1C:Enterprise/OneScript code example"
Image = "https://api.athenaeum.digital/test_data/picture.jpg";
OPI_TypeConversion.GetBinaryData(Image); // Image - Type: BinaryData
PictureFile = GetTempFileName("png");
Image.Write(PictureFile); // PictureFile - File to disk
Base = "C:\Users\Administrator\AppData\Local\Temp\v8_E607_1d.sqlite";
Table = "test";
DataArray = New Array;
RowStructure2 = New Structure;
RowStructure2.Insert("name" , "Vitaly"); // TEXT
RowStructure2.Insert("age" , 25); // INTEGER
RowStructure2.Insert("salary" , 1000.12); // REAL
RowStructure2.Insert("is_active" , True); // BOOL
RowStructure2.Insert("created_at", OPI_Tools.GetCurrentDate()); // DATETIME
RowStructure2.Insert("data" , Image); // BLOB
RowStrucutre1 = New Structure;
RowStrucutre1.Insert("name" , "Lesha") ; // TEXT
RowStrucutre1.Insert("age" , 20); // INTEGER
RowStrucutre1.Insert("salary" , 200.20) ; // REAL
RowStrucutre1.Insert("is_active" , False) ; // BOOL
RowStrucutre1.Insert("created_at", OPI_Tools.GetCurrentDate()); // DATETIME
RowStrucutre1.Insert("data" , New Structure("blob", PictureFile)); // BLOB
DataArray.Add(RowStructure2);
DataArray.Add(RowStrucutre1);
Result = OPI_SQLite.AddRecords(Table, DataArray, , Base);
```
<Tabs>
<TabItem value="bash" label="Bash" default>
```bash
oint sqlite AddRecords \
--table "test" \
--rows "[{'name':'Vitaly','age':25,'salary':1000.12,'is_active':true,'created_at':'2025-01-10T11:19:16.0388392Z','data':{'blob':'C:\\Users\\Administrator\\AppData\\Local\\Temp\\u3k1xzfoorg.png'}},{'name':'Lesha','age':20,'salary':200.20,'is_active':false,'created_at':'2025-01-10T11:19:16.0398417Z','data':{'blob':'C:\\Users\\Administrator\\AppData\\Local\\Temp\\u3k1xzfoorg.png'}}]" \
--db "C:\Users\Administrator\AppData\Local\Temp\3pbdgv5r4nm.sqlite"
```
</TabItem>
<TabItem value="bat" label="CMD/Bat" default>
```batch
oint sqlite AddRecords ^
--table "test" ^
--rows "[{'name':'Vitaly','age':25,'salary':1000.12,'is_active':true,'created_at':'2025-01-10T11:19:16.0388392Z','data':{'blob':'C:\\Users\\Administrator\\AppData\\Local\\Temp\\u3k1xzfoorg.png'}},{'name':'Lesha','age':20,'salary':200.20,'is_active':false,'created_at':'2025-01-10T11:19:16.0398417Z','data':{'blob':'C:\\Users\\Administrator\\AppData\\Local\\Temp\\u3k1xzfoorg.png'}}]" ^
--db "C:\Users\Administrator\AppData\Local\Temp\3pbdgv5r4nm.sqlite"
```
</TabItem>
</Tabs>
```json title="Result"
{
"commit": {
"result": true
},
"result": true,
"rows": 2,
"errors": []
}
```