1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2025-11-25 22:12:29 +02:00
Files
OpenIntegrations/docs/en/md/SQLite/Orm/Ensure-table.mdx
Vitaly the Alpaca (bot) 9be4b23629 Main build (Jenkins)
2025-10-31 15:42:42 +03:00

86 lines
2.6 KiB
Plaintext
Vendored

---
sidebar_position: 5
description: Ensure table and other functions to work with SQLite 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, SQLite]
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Ensure table
Creates a new table if it does not exist or updates the composition of columns in an existing table
`Function EnsureTable(Val Table, Val ColoumnsStruct, Val Connection = "") Export`
| Parameter | CLI option | Type | Required | Description |
|-|-|-|-|-|
| Table | --table | String | ✔ | Table name |
| ColoumnsStruct | --cols | Structure Of KeyAndValue | ✔ | Column structure: Key > Name, Value > Data type |
| Connection | --db | String, Arbitrary | ✖ | Existing connection or database path |
Returns: Map Of KeyAndValue - Result of query execution
<br/>
:::tip
As a result of changing the table structure, data may be lost! It is recommended to test this method on test data beforehand
This function does not update the data type of existing columns
:::
<br/>
```bsl title="1C:Enterprise/OneScript code example"
Base = "C:\Users\bayse\AppData\Local\Temp\v8_2B38_2c.sqlite";
Table = "test";
ColoumnsStruct = New Structure;
ColoumnsStruct.Insert("id" , "INTEGER");
ColoumnsStruct.Insert("code" , "INTEGER");
ColoumnsStruct.Insert("name" , "TEXT");
ColoumnsStruct.Insert("age" , "INTEGER");
ColoumnsStruct.Insert("info" , "TEXT");
Result = OPI_SQLite.EnsureTable(Table, ColoumnsStruct, Base);
```
<Tabs>
<TabItem value="bash" label="Bash" default>
```bash
# JSON data can also be passed as a path to a .json file
oint sqlite EnsureTable \
--table "test_new" \
--cols "{'id':'INTEGER','code':'INTEGER','name':'TEXT','age':'INTEGER','info':'TEXT'}" \
--db "C:\Users\bayse\AppData\Local\Temp\3haxtz5d.4nv.sqlite"
```
</TabItem>
<TabItem value="bat" label="CMD/Bat" default>
```batch
:: JSON data can also be passed as a path to a .json file
oint sqlite EnsureTable ^
--table "test_new" ^
--cols "{'id':'INTEGER','code':'INTEGER','name':'TEXT','age':'INTEGER','info':'TEXT'}" ^
--db "C:\Users\bayse\AppData\Local\Temp\3haxtz5d.4nv.sqlite"
```
</TabItem>
</Tabs>
```json title="Result"
{
"result": true,
"commit": {
"result": true
}
}
```