Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move dataTypeGen to sbvrTypes and use it from there #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions AbstractSQLCompiler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,6 @@
else
Promise.rejected('is an unsupported type: ' + dataType)

dataTypeGen = (engine, dataType, necessity, index = '', defaultValue) ->
necessity = if necessity then ' NOT NULL' else ' NULL'
defaultValue = if defaultValue then " DEFAULT #{defaultValue}"
if index != ''
index = ' ' + index
dbType = sbvrTypes[dataType]?.types?[engine]
if dbType?
if _.isFunction(dbType)
return dbType(necessity, index)
defaultValue ?= ''
return dbType + defaultValue + necessity + index
else
throw new Error("Unknown data type '#{dataType}' for engine: #{engine}")

compileRule = do ->
optimiser = AbstractSQLOptimiser.createInstance()
compiler = AbstractSQLRules2SQL.createInstance()
Expand All @@ -73,7 +59,7 @@
createSQL = 'CREATE TABLE ' + ifNotExists + '"' + table.name + '" (\n\t'

for { dataType, fieldName, required, index, references, defaultValue } in table.fields
createSQL += '"' + fieldName + '" ' + dataTypeGen(engine, dataType, required, index, defaultValue) + '\n,\t'
createSQL += '"' + fieldName + '" ' + sbvrTypes[dataType].dataTypeGen(engine, dataType, required, index, defaultValue) + '\n,\t'
if dataType in [ 'ForeignKey', 'ConceptType' ]
foreignKeys.push({ fieldName, references })
depends.push(references.tableName)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Move dataTypeGen function to sbvr-types module

v2.2.0

* Added support for numbered binds.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"repository": "https://github.com/resin-io-modules/abstract-sql-compiler.git",
"author": "",
"dependencies": {
"@resin/sbvr-types": "^1.0.0",
"@resin/sbvr-types": "^1.3.0",
"bluebird": "^3.0.6",
"lodash": "^4.0.0",
"ometa-js": "^1.4.1"
Expand Down