1
0
mirror of https://github.com/Bayselonarrend/OpenIntegrations.git synced 2026-06-18 05:04:13 +02:00
Files
OpenIntegrations/docs/en/md/SQLite/Table-management/Ensure-table.mdx
T
Vitaly the Alpaca (bot) f06bab8da9 Main build (Jenkins)
2026-05-16 10:53:43 +03:00

106 lines
3.2 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';
import Admonition from '@theme/Admonition';
# Ensure table
Creates a new table if it does not exist or updates the composition of columns in an existing table
<Tabs>
<TabItem value="params" label="Parameters" default>
`Function EnsureTable(Val Table, Val ColoumnsStruct, Val Connection = "") Export`
| Parameter | CLI option | Type | Required | Description |
|-|-|-|-|-|
| Table | --table | String | &#x2714; | Table name |
| ColoumnsStruct | --cols | Structure Of KeyAndValue | &#x2714; | Column structure: Key > Name, Value > Data type |
| Connection | --db | String, Arbitrary | &#x2716; | Existing connection or database path |
<div className="return-value-note">
<div className="return-value-note__title">Returns</div>
<div className="return-value-note__value">
Map Of KeyAndValue - Result of query execution
</div>
</div>
</TabItem>
<TabItem value="extended" label={<span>Advanced call{' '}<a href="/docs/Start/Advanced-call" target="_blank" rel="noreferrer" title="About advanced call" onClick={(e) => e.stopPropagation()}>?</a></span>}>
| Parameter | Description |
|---|---|
| addin_mode | Manual selection of external component connection mode (for 1C): Isolated, NotIsolated |
| dontwait | Creates a background job and returns its data (for 1C and OneScript only) |
</TabItem>
</Tabs>
:::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 = "/tmp/vnnmoosn.qqb.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 "/tmp/cyw3g5s1.luc.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 "/tmp/cyw3g5s1.luc.sqlite"
```
</TabItem>
</Tabs>
```json title="Result"
{
"result": true,
"commit": {
"result": true
}
}
```