-
Notifications
You must be signed in to change notification settings - Fork 4
/
stmt_table.go
636 lines (570 loc) · 20.7 KB
/
stmt_table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
package godynamo
import (
"context"
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"io"
"reflect"
"sort"
"strconv"
"strings"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/btnguyen2k/consu/reddo"
)
// internal use!
type lsiDef struct {
indexName, attrName, attrType string
projectedAttrs string
}
/*----------------------------------------------------------------------*/
// StmtCreateTable implements "CREATE TABLE" statement.
//
// Syntax:
//
// CREATE TABLE [IF NOT EXISTS] <table-name>
// <WITH PK=pk-attr-name:data-type>
// [[,] WITH SK=sk-attr-name:data-type]
// [[,] WITH wcu=<number>[,] WITH rcu=<number>]
// [[,] WITH LSI=index-name1:attr-name1:data-type]
// [[,] WITH LSI=index-name2:attr-name2:data-type:*]
// [[,] WITH LSI=index-name2:attr-name2:data-type:nonKeyAttr1,nonKeyAttr2,nonKeyAttr3,...]
// [[,] WITH LSI...]
// [[,] WITH CLASS=<table-class>]
//
// - PK: partition key, format name:type (type is one of String, Number, Binary).
// - SK: sort key, format name:type (type is one of String, Number, Binary).
// - LSI: local secondary index, format index-name:attr-name:type[:projectionAttrs], where:
// - type is one of String, Number, Binary.
// - projectionAttrs=*: all attributes from the original table are included in projection (ProjectionType=ALL).
// - projectionAttrs=attr1,attr2,...: specified attributes from the original table are included in projection (ProjectionType=INCLUDE).
// - projectionAttrs is not specified: only key attributes are included in projection (ProjectionType=KEYS_ONLY).
// - RCU: an integer specifying DynamoDB's read capacity.
// - WCU: an integer specifying DynamoDB's write capacity.
// - CLASS: table class, either STANDARD (default) or STANDARD_IA.
// - If "IF NOT EXISTS" is specified, Exec will silently swallow the error "ResourceInUseException".
// - Note: if RCU and WRU are both 0 or not specified, table will be created with PAY_PER_REQUEST billing mode; otherwise table will be creatd with PROVISIONED mode.
// - Note: there must be at least one space before the WITH keyword.
type StmtCreateTable struct {
*Stmt
tableName string
ifNotExists bool
pkName, pkType string
tableClass *string
skName, skType *string
rcu, wcu *int64
lsi []lsiDef
withOptsStr string
}
func (s *StmtCreateTable) parse() error {
if err := s.Stmt.parseWithOpts(s.withOptsStr); err != nil {
return err
}
// partition key
pkTokens := strings.SplitN(s.withOpts["PK"].FirstString(), ":", 2)
s.pkName = strings.TrimSpace(pkTokens[0])
if len(pkTokens) > 1 {
s.pkType = strings.TrimSpace(strings.ToUpper(pkTokens[1]))
}
if s.pkName == "" {
return fmt.Errorf("no PartitionKey, specify one using WITH pk=pkname:pktype")
}
if _, ok := dataTypes[s.pkType]; !ok {
return fmt.Errorf("invalid type <%s> for PartitionKey, accepts values are BINARY, NUMBER and STRING", s.pkType)
}
// sort key
skTokens := strings.SplitN(s.withOpts["SK"].FirstString(), ":", 2)
skName := strings.TrimSpace(skTokens[0])
if skName != "" {
s.skName = &skName
skType := ""
if len(skTokens) > 1 {
skType = strings.TrimSpace(strings.ToUpper(skTokens[1]))
}
if _, ok := dataTypes[skType]; !ok {
return fmt.Errorf("invalid type SortKey <%s>, accepts values are BINARY, NUMBER and STRING", skType)
}
s.skType = &skType
}
// local secondary index
for _, lsiStr := range s.withOpts["LSI"] {
lsiTokens := strings.SplitN(lsiStr, ":", 4)
lsiDef := lsiDef{indexName: strings.TrimSpace(lsiTokens[0])}
if len(lsiTokens) > 1 {
lsiDef.attrName = strings.TrimSpace(lsiTokens[1])
}
if len(lsiTokens) > 2 {
lsiDef.attrType = strings.TrimSpace(strings.ToUpper(lsiTokens[2]))
}
if len(lsiTokens) > 3 {
lsiDef.projectedAttrs = strings.TrimSpace(lsiTokens[3])
}
if lsiDef.indexName != "" {
if lsiDef.attrName == "" {
return fmt.Errorf("invalid LSI definition <%s>: empty field name", lsiDef.indexName)
}
if _, ok := dataTypes[lsiDef.attrType]; !ok {
return fmt.Errorf("invalid type <%s> of LSI <%s>, accepts values are BINARY, NUMBER and STRING", lsiDef.attrType, lsiDef.indexName)
}
}
s.lsi = append(s.lsi, lsiDef)
}
// table class
if _, ok := s.withOpts["CLASS"]; ok {
tableClass := strings.ToUpper(s.withOpts["CLASS"].FirstString())
if tableClasses[tableClass] == "" {
return fmt.Errorf("invalid table class <%s>, accepts values are STANDARD, STANDARD_IA", s.withOpts["CLASS"].FirstString())
}
s.tableClass = &tableClass
}
// RCU
if _, ok := s.withOpts["RCU"]; ok {
rcu, err := strconv.ParseInt(s.withOpts["RCU"].FirstString(), 10, 64)
if err != nil || rcu < 0 {
return fmt.Errorf("invalid RCU value: %s", s.withOpts["RCU"])
}
s.rcu = &rcu
}
// WCU
if _, ok := s.withOpts["WCU"]; ok {
wcu, err := strconv.ParseInt(s.withOpts["WCU"].FirstString(), 10, 64)
if err != nil || wcu < 0 {
return fmt.Errorf("invalid WCU value: %s", s.withOpts["WCU"])
}
s.wcu = &wcu
}
return nil
}
func (s *StmtCreateTable) validate() error {
if s.tableName == "" {
return errors.New("table name is missing")
}
return nil
}
// Query implements driver.Stmt/Query.
// This function is not implemented, use Exec instead.
func (s *StmtCreateTable) Query(_ []driver.Value) (driver.Rows, error) {
return nil, errors.New("this operation is not supported, please use Exec")
}
// QueryContext implements driver.StmtQueryContext/QueryContext.
// This function is not implemented, use ExecContext instead.
func (s *StmtCreateTable) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error) {
return nil, errors.New("this operation is not supported, please use ExecContext")
}
// Exec implements driver.Stmt/Exec.
func (s *StmtCreateTable) Exec(_ []driver.Value) (driver.Result, error) {
return s.ExecContext(s.conn.newContext(), nil)
}
// ExecContext implements driver.StmtExecContext/Exec.
//
// @Available since v0.2.0
func (s *StmtCreateTable) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error) {
attrDefs := make([]types.AttributeDefinition, 0, 2)
attrDefs = append(attrDefs, types.AttributeDefinition{AttributeName: &s.pkName, AttributeType: dataTypes[s.pkType]})
keySchema := make([]types.KeySchemaElement, 0, 2)
keySchema = append(keySchema, types.KeySchemaElement{AttributeName: &s.pkName, KeyType: keyTypes["HASH"]})
if s.skName != nil {
attrDefs = append(attrDefs, types.AttributeDefinition{AttributeName: s.skName, AttributeType: dataTypes[*s.skType]})
keySchema = append(keySchema, types.KeySchemaElement{AttributeName: s.skName, KeyType: keyTypes["RANGE"]})
}
lsi := make([]types.LocalSecondaryIndex, len(s.lsi))
if len(s.lsi) == 0 {
lsi = nil
}
for i := range s.lsi {
attrDefs = append(attrDefs, types.AttributeDefinition{AttributeName: &s.lsi[i].attrName, AttributeType: dataTypes[s.lsi[i].attrType]})
lsi[i] = types.LocalSecondaryIndex{
IndexName: &s.lsi[i].indexName,
KeySchema: []types.KeySchemaElement{
{AttributeName: &s.pkName, KeyType: keyTypes["HASH"]},
{AttributeName: &s.lsi[i].attrName, KeyType: keyTypes["RANGE"]},
},
Projection: &types.Projection{ProjectionType: types.ProjectionTypeKeysOnly},
}
if s.lsi[i].projectedAttrs == "*" {
lsi[i].Projection.ProjectionType = types.ProjectionTypeAll
} else if s.lsi[i].projectedAttrs != "" {
lsi[i].Projection.ProjectionType = types.ProjectionTypeInclude
nonKeyAttrs := strings.Split(s.lsi[i].projectedAttrs, ",")
lsi[i].Projection.NonKeyAttributes = nonKeyAttrs
}
}
input := &dynamodb.CreateTableInput{
TableName: &s.tableName,
AttributeDefinitions: attrDefs,
KeySchema: keySchema,
LocalSecondaryIndexes: lsi,
}
if s.tableClass != nil {
input.TableClass = tableClasses[*s.tableClass]
}
if (s.rcu == nil || *s.rcu == 0) && (s.wcu == nil || *s.wcu == 0) {
input.BillingMode = types.BillingModePayPerRequest
} else {
input.BillingMode = types.BillingModeProvisioned
input.ProvisionedThroughput = &types.ProvisionedThroughput{
ReadCapacityUnits: s.rcu,
WriteCapacityUnits: s.wcu,
}
}
_, err := s.conn.client.CreateTable(s.conn.ensureContext(ctx), input)
affectedRows := int64(0)
if err == nil {
affectedRows = 1
}
if s.ifNotExists && IsAwsError(err, "ResourceInUseException") {
err = nil
}
return &ResultNoResultSet{err: err, affectedRows: affectedRows}, err
}
/*----------------------------------------------------------------------*/
// StmtListTables implements "LIST TABLES" statement.
//
// Syntax:
//
// LIST TABLES|TABLE
type StmtListTables struct {
*Stmt
}
func (s *StmtListTables) validate() error {
return nil
}
// Exec implements driver.Stmt/Exec.
// This function is not implemented, use Query instead.
func (s *StmtListTables) Exec(_ []driver.Value) (driver.Result, error) {
return nil, errors.New("this operation is not supported, please use Query")
}
// ExecContext implements driver.StmtExecContext/Exec.
// This function is not implemented, use QueryContext instead.
func (s *StmtListTables) ExecContext(_ context.Context, _ []driver.NamedValue) (driver.Result, error) {
return nil, errors.New("this operation is not supported, please use QueryContext")
}
// Query implements driver.Stmt/Query.
func (s *StmtListTables) Query(_ []driver.Value) (driver.Rows, error) {
return s.QueryContext(s.conn.newContext(), nil)
}
// QueryContext implements driver.StmtQueryContext/QueryContext.
//
// @Available since v0.2.0
func (s *StmtListTables) QueryContext(ctx context.Context, _ []driver.NamedValue) (driver.Rows, error) {
output, err := s.conn.client.ListTables(s.conn.ensureContext(ctx), &dynamodb.ListTablesInput{})
var rows driver.Rows
if err == nil {
rows = &RowsListTables{
count: len(output.TableNames),
tables: output.TableNames,
cursorCount: 0,
}
sort.Strings(rows.(*RowsListTables).tables)
}
return rows, err
}
// RowsListTables captures the result from LIST TABLES statement.
type RowsListTables struct {
count int
tables []string
cursorCount int
}
// Columns implements driver.Rows/Columns.
func (r *RowsListTables) Columns() []string {
return []string{"$1"}
}
// Close implements driver.Rows/Close.
func (r *RowsListTables) Close() error {
return nil
}
// Next implements driver.Rows/Next.
func (r *RowsListTables) Next(dest []driver.Value) error {
if r.cursorCount >= r.count {
return io.EOF
}
rowData := r.tables[r.cursorCount]
r.cursorCount++
dest[0] = rowData
return nil
}
// ColumnTypeScanType implements driver.RowsColumnTypeScanType/ColumnTypeScanType
func (r *RowsListTables) ColumnTypeScanType(_ int) reflect.Type {
return reddo.TypeString
}
// ColumnTypeDatabaseTypeName implements driver.RowsColumnTypeDatabaseTypeName/ColumnTypeDatabaseTypeName
func (r *RowsListTables) ColumnTypeDatabaseTypeName(_ int) string {
return "STRING"
}
/*----------------------------------------------------------------------*/
// StmtAlterTable implements "ALTER TABLE" statement.
//
// Syntax:
//
// ALTER TABLE <table-name>
// [WITH RCU=rcu[,] WITH WCU=wcu]
// [[,] WITH CLASS=<table-class>]
//
// - RCU: an integer specifying DynamoDB's read capacity.
// - WCU: an integer specifying DynamoDB's write capacity.
// - CLASS: table class, either STANDARD (default) or STANDARD_IA.
// - Note: if RCU and WRU are both 0, table's billing mode will be updated to PAY_PER_REQUEST; otherwise billing mode will be updated to PROVISIONED.
// - Note: there must be at least one space before the WITH keyword.
type StmtAlterTable struct {
*Stmt
tableName string
rcu, wcu *int64
tableClass *string
withOptsStr string
}
func (s *StmtAlterTable) parse() error {
if err := s.Stmt.parseWithOpts(s.withOptsStr); err != nil {
return err
}
// table class
if _, ok := s.withOpts["CLASS"]; ok {
tableClass := strings.ToUpper(s.withOpts["CLASS"].FirstString())
if tableClasses[tableClass] == "" {
return fmt.Errorf("invalid table class <%s>, accepts values are STANDARD, STANDARD_IA", s.withOpts["CLASS"].FirstString())
}
s.tableClass = &tableClass
}
// RCU
if _, ok := s.withOpts["RCU"]; ok {
rcu, err := strconv.ParseInt(s.withOpts["RCU"].FirstString(), 10, 64)
if err != nil || rcu < 0 {
return fmt.Errorf("invalid RCU value: %s", s.withOpts["RCU"])
}
s.rcu = &rcu
}
// WCU
if _, ok := s.withOpts["WCU"]; ok {
wcu, err := strconv.ParseInt(s.withOpts["WCU"].FirstString(), 10, 64)
if err != nil || wcu < 0 {
return fmt.Errorf("invalid WCU value: %s", s.withOpts["WCU"])
}
s.wcu = &wcu
}
return nil
}
func (s *StmtAlterTable) validate() error {
if s.tableName == "" {
return errors.New("table name is missing")
}
return nil
}
// Query implements driver.Stmt/Query.
// This function is not implemented, use Exec instead.
func (s *StmtAlterTable) Query(_ []driver.Value) (driver.Rows, error) {
return nil, errors.New("this operation is not supported, please use Exec")
}
// QueryContext implements driver.StmtQueryContext/QueryContext.
// This function is not implemented, use ExecContext instead.
func (s *StmtAlterTable) QueryContext(_ []driver.NamedValue) (driver.Rows, error) {
return nil, errors.New("this operation is not supported, please use ExecContext")
}
// Exec implements driver.Stmt/Exec.
func (s *StmtAlterTable) Exec(_ []driver.Value) (driver.Result, error) {
return s.ExecContext(s.conn.newContext(), nil)
}
// ExecContext implements driver.StmtExecContext/ExecContext.
//
// @Available since v0.2.0
func (s *StmtAlterTable) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error) {
input := &dynamodb.UpdateTableInput{
TableName: &s.tableName,
}
if s.tableClass != nil {
input.TableClass = tableClasses[*s.tableClass]
}
if s.rcu != nil || s.wcu != nil {
if s.rcu != nil && *s.rcu == 0 && s.wcu != nil && *s.wcu == 0 {
input.BillingMode = types.BillingModePayPerRequest
} else {
input.BillingMode = types.BillingModeProvisioned
input.ProvisionedThroughput = &types.ProvisionedThroughput{
ReadCapacityUnits: s.rcu,
WriteCapacityUnits: s.wcu,
}
}
}
_, err := s.conn.client.UpdateTable(s.conn.ensureContext(ctx), input)
affectedRows := int64(0)
if err == nil {
affectedRows = 1
}
return &ResultNoResultSet{err: err, affectedRows: affectedRows}, err
}
/*----------------------------------------------------------------------*/
// StmtDropTable implements "DROP TABLE" statement.
//
// Syntax:
//
// DROP TABLE [IF EXISTS] <table-name>
//
// If "IF EXISTS" is specified, Exec will silently swallow the error "ResourceNotFoundException".
type StmtDropTable struct {
*Stmt
tableName string
ifExists bool
}
func (s *StmtDropTable) validate() error {
if s.tableName == "" {
return errors.New("table name is missing")
}
return nil
}
// Query implements driver.Stmt/Query.
// This function is not implemented, use Exec instead.
func (s *StmtDropTable) Query(_ []driver.Value) (driver.Rows, error) {
return nil, errors.New("this operation is not supported, please use Exec")
}
// QueryContext implements driver.StmtQueryContext/QueryContext.
// This function is not implemented, use ExecContext instead.
func (s *StmtDropTable) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error) {
return nil, errors.New("this operation is not supported, please use ExecContext")
}
// Exec implements driver.Stmt/Exec.
func (s *StmtDropTable) Exec(_ []driver.Value) (driver.Result, error) {
return s.ExecContext(s.conn.newContext(), nil)
}
// ExecContext implements driver.StmtExecContext/Exec.
//
// @Available since v0.2.0
func (s *StmtDropTable) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error) {
input := &dynamodb.DeleteTableInput{
TableName: &s.tableName,
}
_, err := s.conn.client.DeleteTable(s.conn.ensureContext(ctx), input)
affectedRows := int64(0)
if err == nil {
affectedRows = 1
}
if s.ifExists && IsAwsError(err, "ResourceNotFoundException") {
err = nil
}
return &ResultNoResultSet{err: err, affectedRows: affectedRows}, err
}
/*----------------------------------------------------------------------*/
// StmtDescribeTable implements "DESCRIBE TABLE" operation.
//
// Syntax:
//
// DESCRIBE TABLE <table-name>
type StmtDescribeTable struct {
*Stmt
tableName string
}
func (s *StmtDescribeTable) validate() error {
if s.tableName == "" {
return errors.New("table name is missing")
}
return nil
}
// Exec implements driver.Stmt/Exec.
// This function is not implemented, use Query instead.
func (s *StmtDescribeTable) Exec(_ []driver.Value) (driver.Result, error) {
return nil, errors.New("this operation is not supported, please use Query")
}
// ExecContext implements driver.StmtExecContext/ExecContext.
// This function is not implemented, use QueryContext instead.
func (s *StmtDescribeTable) ExecContext(_ context.Context, _ []driver.NamedValue) (driver.Result, error) {
return nil, errors.New("this operation is not supported, please use QueryContext")
}
// Query implements driver.Stmt/Query.
func (s *StmtDescribeTable) Query(_ []driver.Value) (driver.Rows, error) {
return s.QueryContext(s.conn.newContext(), nil)
}
// QueryContext implements driver.StmtQueryContext/Query.
//
// @Available since v0.2.0
func (s *StmtDescribeTable) QueryContext(ctx context.Context, _ []driver.NamedValue) (driver.Rows, error) {
input := &dynamodb.DescribeTableInput{
TableName: &s.tableName,
}
output, err := s.conn.client.DescribeTable(s.conn.ensureContext(ctx), input)
result := &RowsDescribeTable{count: 0}
if err == nil {
result.count = 1
js, _ := json.Marshal(output.Table)
_ = json.Unmarshal(js, &result.tableInfo)
result.columnList = make([]string, 0)
result.columnTypes = make(map[string]reflect.Type)
result.columnSourceTypes = make(map[string]string)
for col, spec := range dynamodbTableSpec {
result.columnList = append(result.columnList, col)
result.columnTypes[col] = spec.scanType
result.columnSourceTypes[col] = spec.srcType
}
sort.Strings(result.columnList)
}
if IsAwsError(err, "ResourceNotFoundException") {
err = nil
}
return result, err
}
var (
dynamodbTableSpec = map[string]struct {
scanType reflect.Type
srcType string
}{
"ArchivalSummary": {srcType: "M", scanType: typeM},
"AttributeDefinitions": {srcType: "L", scanType: typeL},
"BillingModeSummary": {srcType: "M", scanType: typeM},
"CreationDateTime": {srcType: "S", scanType: typeTime},
"DeletionProtectionEnabled": {srcType: "BOOL", scanType: typeBool},
"GlobalSecondaryIndexes": {srcType: "L", scanType: typeL},
"GlobalTableVersion": {srcType: "S", scanType: typeS},
"ItemCount": {srcType: "N", scanType: typeN},
"KeySchema": {srcType: "L", scanType: typeL},
"LatestStreamArn": {srcType: "S", scanType: typeS},
"LatestStreamLabel": {srcType: "S", scanType: typeS},
"LocalSecondaryIndexes": {srcType: "L", scanType: typeL},
"ProvisionedThroughput": {srcType: "M", scanType: typeM},
"Replicas": {srcType: "L", scanType: typeL},
"RestoreSummary": {srcType: "M", scanType: typeM},
"SSEDescription": {srcType: "M", scanType: typeM},
"StreamSpecification": {srcType: "M", scanType: typeM},
"TableArn": {srcType: "S", scanType: typeS},
"TableClassSummary": {srcType: "M", scanType: typeM},
"TableId": {srcType: "S", scanType: typeS},
"TableName": {srcType: "S", scanType: typeS},
"TableSizeBytes": {srcType: "N", scanType: typeN},
"TableStatus": {srcType: "S", scanType: typeS},
}
)
// RowsDescribeTable captures the result from DESCRIBE TABLE statement.
type RowsDescribeTable struct {
count int
columnList []string
columnTypes map[string]reflect.Type
columnSourceTypes map[string]string
tableInfo map[string]interface{}
cursorCount int
}
// Columns implements driver.Rows/Columns.
func (r *RowsDescribeTable) Columns() []string {
return r.columnList
}
// Close implements driver.Rows/Close.
func (r *RowsDescribeTable) Close() error {
return nil
}
// Next implements driver.Rows/Next.
func (r *RowsDescribeTable) Next(dest []driver.Value) error {
if r.cursorCount >= r.count {
return io.EOF
}
for i, colName := range r.columnList {
dest[i] = r.tableInfo[colName]
}
r.cursorCount++
return nil
}
// ColumnTypeScanType implements driver.RowsColumnTypeScanType/ColumnTypeScanType
func (r *RowsDescribeTable) ColumnTypeScanType(index int) reflect.Type {
return r.columnTypes[r.columnList[index]]
}
// ColumnTypeDatabaseTypeName implements driver.RowsColumnTypeDatabaseTypeName/ColumnTypeDatabaseTypeName
//
// @since v0.3.0 ColumnTypeDatabaseTypeName returns DynamoDB's native data types (e.g. B, N, S, SS, NS, BS, BOOL, L, M, NULL).
func (r *RowsDescribeTable) ColumnTypeDatabaseTypeName(index int) string {
return r.columnSourceTypes[r.columnList[index]]
}