(model)
| 388 | |
| 389 | |
| 390 | def _get_create_table(model): |
| 391 | ks_table_name = model.column_family_name() |
| 392 | query_strings = ['CREATE TABLE {0}'.format(ks_table_name)] |
| 393 | |
| 394 | # add column types |
| 395 | pkeys = [] # primary keys |
| 396 | ckeys = [] # clustering keys |
| 397 | qtypes = [] # field types |
| 398 | |
| 399 | def add_column(col): |
| 400 | s = col.get_column_def() |
| 401 | if col.primary_key: |
| 402 | keys = (pkeys if col.partition_key else ckeys) |
| 403 | keys.append('"{0}"'.format(col.db_field_name)) |
| 404 | qtypes.append(s) |
| 405 | |
| 406 | for name, col in model._columns.items(): |
| 407 | add_column(col) |
| 408 | |
| 409 | qtypes.append('PRIMARY KEY (({0}){1})'.format(', '.join(pkeys), ckeys and ', ' + ', '.join(ckeys) or '')) |
| 410 | |
| 411 | query_strings += ['({0})'.format(', '.join(qtypes))] |
| 412 | |
| 413 | property_strings = [] |
| 414 | |
| 415 | _order = ['"{0}" {1}'.format(c.db_field_name, c.clustering_order or 'ASC') for c in model._clustering_keys.values()] |
| 416 | if _order: |
| 417 | property_strings.append('CLUSTERING ORDER BY ({0})'.format(', '.join(_order))) |
| 418 | |
| 419 | # options strings use the V3 format, which matches CQL more closely and does not require mapping |
| 420 | property_strings += metadata.TableMetadataV3._make_option_strings(model.__options__ or {}) |
| 421 | |
| 422 | if property_strings: |
| 423 | query_strings += ['WITH {0}'.format(' AND '.join(property_strings))] |
| 424 | |
| 425 | return ' '.join(query_strings) |
| 426 | |
| 427 | |
| 428 | def _get_table_metadata(model, connection=None): |
no test coverage detected