Skip to content

Commit 2f9a5b6

Browse files
Fixed some of the examples for ALTER TABLE in README
1 parent 02af894 commit 2f9a5b6

File tree

1 file changed

+59
-54
lines changed

1 file changed

+59
-54
lines changed

README.md

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -170,58 +170,6 @@ await builder.createTable()
170170
// Executes: CREATE TABLE IF NOT EXISTS table_name(column1 String) ENGINE = Memory
171171
```
172172

173-
## INSERT
174-
175-
Builder has special method called `insert()` to handle INSERT queries. Below you may find a couple of examples.
176-
177-
Insert single row:
178-
179-
```ts
180-
await builder.insert()
181-
.into('metrics')
182-
.columns(['id', 'ip', 'created_date'])
183-
.values({id: 1, ip: '127.0.0.1', created_date: '2022-12-20'})
184-
.execute();
185-
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20')
186-
```
187-
188-
Definition of `columns()` is optional, you can use `values()` without it. `values()` will use the first row to determine
189-
the columns.
190-
191-
```ts
192-
await builder.insert()
193-
.into('metrics')
194-
.values({id: 1, ip: '127.0.0.1', created_date: '2022-12-20'})
195-
.execute();
196-
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20')
197-
```
198-
199-
You can chain multiple rows using `values()`:
200-
201-
```ts
202-
await builder.insert()
203-
.into('metrics')
204-
.columns(['id', 'ip', 'created_date'])
205-
.values({id: 1, ip: '127.0.0.1', created_date: '2022-12-20'})
206-
.values({id: 2, ip: '127.0.0.2', created_date: '2022-12-21'})
207-
.execute();
208-
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20'), (2, '127.0.0.2', '2022-12-21')
209-
```
210-
211-
You can write bulk rows (same as above):
212-
213-
```ts
214-
await builder.insert()
215-
.into('metrics')
216-
.columns(['id', 'ip', 'created_date'])
217-
.values([
218-
{id: 1, ip: '127.0.0.1', created_date: '2022-12-20'},
219-
{id: 2, ip: '127.0.0.2', created_date: '2022-12-21'}
220-
])
221-
.execute();
222-
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20'), (2, '127.0.0.2', '2022-12-21')
223-
```
224-
225173
## ALTER TABLE
226174

227175
Builder has special method called `alterTable()` to handle ALTER TABLE queries. Below you may find a couple of examples.
@@ -230,7 +178,7 @@ Add column:
230178

231179
```ts
232180
import {schema} from 'clickhouse-query';
233-
import {AddColumn} from './AddColumn';
181+
import {AddColumn} from 'clickhouse-query/AlterTable/AddColumn';
234182

235183
await builder.alterTable()
236184
.table('table_name')
@@ -242,6 +190,8 @@ await builder.alterTable()
242190
Drop column:
243191

244192
```ts
193+
import {DropColumn} from 'clickhouse-query/AlterTable/DropColumn';
194+
245195
await builder.alterTable()
246196
.table('table_name')
247197
.dropColumn((new DropColumn()).name('column1'))
@@ -252,7 +202,7 @@ await builder.alterTable()
252202
Rename column:
253203

254204
```ts
255-
import {RenameColumn} from './RenameColumn';
205+
import {RenameColumn} from 'clickhouse-query/AlterTable/RenameColumn';
256206

257207
await builder.alterTable()
258208
.table('table_name')
@@ -265,6 +215,7 @@ Modify column:
265215

266216
```ts
267217
import {schema} from 'clickhouse-query';
218+
import {ModifyColumn} from 'clickhouse-query/AlterTable/ModifyColumn';
268219

269220
await builder.alterTable()
270221
.table('table_name')
@@ -277,6 +228,7 @@ Modify column with `AFTER`:
277228

278229
```ts
279230
import {schema} from 'clickhouse-query';
231+
import {ModifyColumn} from 'clickhouse-query/AlterTable/ModifyColumn';
280232

281233
await builder.alterTable()
282234
.table('table_name')
@@ -290,6 +242,7 @@ Modify column with `FIRST`:
290242

291243
```ts
292244
import {schema} from 'clickhouse-query';
245+
import {ModifyColumn} from 'clickhouse-query/AlterTable/ModifyColumn';
293246

294247
await builder.alterTable()
295248
.table('table_name')
@@ -299,6 +252,58 @@ await builder.alterTable()
299252
// Executes: ALTER TABLE table_name MODIFY COLUMN column1 String FIRST
300253
```
301254

255+
## INSERT
256+
257+
Builder has special method called `insert()` to handle INSERT queries. Below you may find a couple of examples.
258+
259+
Insert single row:
260+
261+
```ts
262+
await builder.insert()
263+
.into('metrics')
264+
.columns(['id', 'ip', 'created_date'])
265+
.values({id: 1, ip: '127.0.0.1', created_date: '2022-12-20'})
266+
.execute();
267+
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20')
268+
```
269+
270+
Definition of `columns()` is optional, you can use `values()` without it. `values()` will use the first row to determine
271+
the columns.
272+
273+
```ts
274+
await builder.insert()
275+
.into('metrics')
276+
.values({id: 1, ip: '127.0.0.1', created_date: '2022-12-20'})
277+
.execute();
278+
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20')
279+
```
280+
281+
You can chain multiple rows using `values()`:
282+
283+
```ts
284+
await builder.insert()
285+
.into('metrics')
286+
.columns(['id', 'ip', 'created_date'])
287+
.values({id: 1, ip: '127.0.0.1', created_date: '2022-12-20'})
288+
.values({id: 2, ip: '127.0.0.2', created_date: '2022-12-21'})
289+
.execute();
290+
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20'), (2, '127.0.0.2', '2022-12-21')
291+
```
292+
293+
You can write bulk rows (same as above):
294+
295+
```ts
296+
await builder.insert()
297+
.into('metrics')
298+
.columns(['id', 'ip', 'created_date'])
299+
.values([
300+
{id: 1, ip: '127.0.0.1', created_date: '2022-12-20'},
301+
{id: 2, ip: '127.0.0.2', created_date: '2022-12-21'}
302+
])
303+
.execute();
304+
// Executes: INSERT INTO metrics (id, ip, created_date) VALUES (1, '127.0.0.1', '2022-12-20'), (2, '127.0.0.2', '2022-12-21')
305+
```
306+
302307
## DELETE
303308

304309
Builder has special method called `delete()` to handle DELETE queries. Below you may find a couple of examples.

0 commit comments

Comments
 (0)