0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Merge pull request #85 from digitalist/ddl2cpp

Ddl2cpp
This commit is contained in:
Roland Bock 2016-05-05 21:38:24 +02:00
commit 7ed4ba9860
2 changed files with 7 additions and 1 deletions

View File

@ -132,6 +132,7 @@ sqlpp11 requires a certain api in order to connect with the database, see databa
* MySQL: https://github.com/rbock/sqlpp11-connector-mysql * MySQL: https://github.com/rbock/sqlpp11-connector-mysql
* Sqlite3: https://github.com/rbock/sqlpp11-connector-sqlite3 * Sqlite3: https://github.com/rbock/sqlpp11-connector-sqlite3
* PostgreSQL: https://github.com/matthijs/sqlpp11-connector-postgresql * PostgreSQL: https://github.com/matthijs/sqlpp11-connector-postgresql
* ODBC: https://github.com/Erroneous1/sqlpp11-connector-odbc (experimental)
To demonstrate that sqlpp11 can work with other backends as well, here is an experimental backend for structs in standard containers: To demonstrate that sqlpp11 can work with other backends as well, here is an experimental backend for structs in standard containers:

View File

@ -80,6 +80,11 @@ def toMemberName(s):
def ddlWord(string): def ddlWord(string):
return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_") return WordStart(alphanums + "_") + CaselessLiteral(string) + WordEnd(alphanums + "_")
# This function should be refactored if we find some database function which needs parameters
# Right now it works only for something like NOW() in MySQL default field value
def ddlFunctionWord(string):
return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")")
ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")])
negativeSign = Literal('-') negativeSign = Literal('-')
ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) ddlNum = Combine(Optional(negativeSign) + Word(nums + "."))
@ -98,7 +103,7 @@ ddlConstraint = Or([
ddlWord("INDEX"), ddlWord("INDEX"),
ddlWord("UNIQUE"), ddlWord("UNIQUE"),
]) ])
ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments])))
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")