-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add releasing/executing multi-query support (#14)
* Rework query-face-template * Tried to make it more readable and effective * Rename as validate-query-template * Add centralized errors management * Rework query-face * Tried to make it more readable and effective * Move some functionst to separate helper files * Update errors * Add whitelistRoutes for devMode * feat: Add anonymous routes to allow testing query * Any logged-in user can test query * feat: Add parameter validations for queries * fix: Remove unnecessary packages * feat: Add releasing/executing multi-query support Add initial data Update qf migrations feat: Add dependent param default value
- Loading branch information
1 parent
8f8e01c
commit e5d9920
Showing
26 changed files
with
1,136 additions
and
916 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const MAIN_DB_NAME = 'qfdb'; | ||
const aliasRegex = /\{\{([a-zA-Z_$][0-9a-zA-Z_$]*)\.([a-zA-Z_$][0-9a-zA-Z_$]*)(:(.*))?\}\}/; | ||
const aliasRegexG = new RegExp(aliasRegex, 'g'); | ||
const paramRegex = /\$\{([_a-zA-Z\s]+)\}/; | ||
const paramPrefixMap = { | ||
QF_CONST: 'qfc', | ||
}; | ||
const queryMap = { | ||
delete: 'from', | ||
update: 'from', | ||
set: 'update', | ||
}; | ||
|
||
const whitelistRoutes = ['get-tables']; | ||
const anonymousRoutes = ['test-query']; | ||
|
||
module.exports = { | ||
MAIN_DB_NAME, | ||
aliasRegexG, | ||
aliasRegex, | ||
anonymousRoutes, | ||
paramRegex, | ||
paramPrefixMap, | ||
queryMap, | ||
whitelistRoutes, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
const path = require('path'); | ||
const databaseMap = {}; | ||
const setDatabase = (dbName, knexDB) => { | ||
databaseMap[dbName] = knexDB; | ||
}; | ||
const setMainDatabase = knexDB => { | ||
databaseMap.qfdb = knexDB; | ||
}; | ||
// try to parse consumer's databases file | ||
try { | ||
const databases = require(path.join(process.cwd(), 'src', 'databases.js')); | ||
if (databases) { | ||
Object.entries(databases).forEach(([name, db]) => { | ||
if (name && db) { | ||
if (name === 'qfdb') { | ||
setMainDatabase(db); | ||
console.log(`[qfdb] MAIN database is set automatically`); | ||
} else { | ||
setDatabase(name, db); | ||
console.log(`[${name}] database is set automatically`); | ||
} | ||
} | ||
}); | ||
} | ||
} catch (error) {} | ||
|
||
module.exports = { | ||
getDatabase: dbName => databaseMap[dbName], | ||
setDatabase: (dbName, knexDB) => { | ||
databaseMap[dbName] = knexDB; | ||
}, | ||
setDatabase, | ||
setMainDatabase, | ||
}; |
Oops, something went wrong.