mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Merge pull request #249 from Erroneous1/feature/split_tables
Add option to ddl2cpp to enable splitting tables
This commit is contained in:
commit
9d430b2e20
@ -85,6 +85,26 @@ def usage(optionalArgs = {}):
|
||||
Usage: ddl2cpp <path to ddl> <path to target (without extension, e.g. /tmp/MyTable)> <namespace>\n\
|
||||
ddl2cpp -help')
|
||||
|
||||
def beginHeader(pathToHeader, nsList):
|
||||
header = open(pathToHeader, 'w')
|
||||
print('// generated by ' + ' '.join(sys.argv), file=header)
|
||||
print('#ifndef '+get_include_guard_name(namespace, pathToHeader), file=header)
|
||||
print('#define '+get_include_guard_name(namespace, pathToHeader), file=header)
|
||||
print('', file=header)
|
||||
print('#include <' + INCLUDE + '/table.h>', file=header)
|
||||
print('#include <' + INCLUDE + '/data_types.h>', file=header)
|
||||
print('#include <' + INCLUDE + '/char_sequence.h>', file=header)
|
||||
print('', file=header)
|
||||
for ns in nsList:
|
||||
print('namespace ' + ns, file=header)
|
||||
print('{', file=header)
|
||||
return header
|
||||
|
||||
def endHeader(header, nsList):
|
||||
for ns in nsList:
|
||||
print('} // namespace ' + ns, file=header)
|
||||
print('#endif', file=header)
|
||||
header.close()
|
||||
|
||||
def help_message():
|
||||
arg_string = '\n'
|
||||
@ -118,6 +138,7 @@ optionalArgs = {
|
||||
'-warn-on-parse': "warn about unusable headers, but continue", # warnOnParse = True
|
||||
'-auto-id': "Assume column 'id' to have an automatic value as if AUTO_INCREMENT was specified (e.g. implicit for SQLite ROWID)", # autoId = True
|
||||
'-identity-naming': "Use table and column names from the ddl (defaults to UpperCamelCase for tables and lowerCamelCase for columns", # identityNaming = True
|
||||
'-split-tables': "Make a header for each table name, using target as a directory", # splitTables = True
|
||||
'-help': "show this help"
|
||||
}
|
||||
|
||||
@ -135,6 +156,7 @@ warnOnParse = False
|
||||
parseError = "Parsing error, possible reason: can't parse default value for a field"
|
||||
autoId = False
|
||||
identityNaming = False
|
||||
splitTables = False
|
||||
|
||||
|
||||
if len(sys.argv) >= 4:
|
||||
@ -155,7 +177,7 @@ if identityNaming:
|
||||
|
||||
pathToDdl = sys.argv[firstPositional]
|
||||
|
||||
pathToHeader = sys.argv[firstPositional + 1] + '.h'
|
||||
pathToHeader = sys.argv[firstPositional + 1] + ('/' if splitTables else '.h')
|
||||
namespace = sys.argv[firstPositional + 2]
|
||||
|
||||
|
||||
@ -297,21 +319,14 @@ def escape_if_reserved(name):
|
||||
# PROCESS DDL
|
||||
tableCreations = ddl.parseFile(pathToDdl)
|
||||
|
||||
header = open(pathToHeader, 'w')
|
||||
print('// generated by ' + ' '.join(sys.argv), file=header)
|
||||
print('#ifndef '+get_include_guard_name(namespace, pathToHeader), file=header)
|
||||
print('#define '+get_include_guard_name(namespace, pathToHeader), file=header)
|
||||
print('', file=header)
|
||||
print('#include <' + INCLUDE + '/table.h>', file=header)
|
||||
print('#include <' + INCLUDE + '/data_types.h>', file=header)
|
||||
print('#include <' + INCLUDE + '/char_sequence.h>', file=header)
|
||||
print('', file=header)
|
||||
for ns in nsList:
|
||||
print('namespace ' + ns, file=header)
|
||||
print('{', file=header)
|
||||
header = 0
|
||||
if not splitTables:
|
||||
header = beginHeader(pathToHeader, nsList)
|
||||
DataTypeError = False
|
||||
for create in tableCreations:
|
||||
sqlTableName = create.tableName
|
||||
if splitTables:
|
||||
header = beginHeader(pathToHeader + sqlTableName + '.h', nsList)
|
||||
tableClass = toClassName(sqlTableName)
|
||||
tableMember = toMemberName(sqlTableName)
|
||||
tableNamespace = tableClass + '_'
|
||||
@ -385,10 +400,11 @@ for create in tableCreations:
|
||||
print(' };', file=header)
|
||||
print(' };', file=header)
|
||||
print(' };', file=header)
|
||||
if splitTables:
|
||||
endHeader(header, nsList)
|
||||
|
||||
for ns in nsList:
|
||||
print('} // namespace ' + ns, file=header)
|
||||
print('#endif', file=header)
|
||||
if not splitTables:
|
||||
endHeader(header, nsList)
|
||||
if (DataTypeError):
|
||||
print("Error: unsupported datatypes." )
|
||||
print("Possible solutions:")
|
||||
|
Loading…
Reference in New Issue
Block a user