Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SOL to the moon
DBGrep
Commits
dbfb9d43
Commit
dbfb9d43
authored
Oct 30, 2021
by
Ennen Chris-Robin
Browse files
Merge branch '2-db-connection' into 'main'
Resolve "DB connection" Closes
#2
See merge request
!2
parents
6b57061d
7d7b9b5f
Pipeline
#27764
passed with stages
in 1 minute and 46 seconds
Changes
5
Pipelines
3
Expand all
Hide whitespace changes
Inline
Side-by-side
package-lock.json
View file @
dbfb9d43
This diff is collapsed.
Click to expand it.
package.json
View file @
dbfb9d43
...
...
@@ -38,8 +38,13 @@
"
typescript
"
:
"
^4.4.4
"
},
"dependencies"
:
{
"
json
"
:
"
^11.0.0
"
,
"
knex
"
:
"
^0.95.11
"
"
knex
"
:
"
^0.95.11
"
,
"
knex-schema-inspector
"
:
"
^1.6.4
"
,
"
mysql
"
:
"
^2.18.1
"
,
"
oracledb
"
:
"
^5.3.0
"
,
"
pg
"
:
"
^8.7.1
"
,
"
sqlite3
"
:
"
^5.0.2
"
,
"
tedious
"
:
"
^14.0.0
"
},
"husky"
:
{
"hooks"
:
{
...
...
src/client/client.test.ts
0 → 100644
View file @
dbfb9d43
import
knex
from
'
knex
'
import
type
{
Knex
}
from
'
knex
'
import
Client
from
'
./client
'
import
type
{
ClientParams
}
from
'
./client
'
jest
.
mock
(
'
knex
'
)
jest
.
mock
(
'
knex-schema-inspector
'
)
describe
(
'
The DB connection client
'
,
()
=>
{
it
(
'
Initialize the knex client with correct parameters
'
,
()
=>
{
const
params
:
ClientParams
=
{
database
:
'
db
'
,
dbtype
:
'
sqlite3
'
,
host
:
'
localhost
'
,
password
:
'
abc123
'
,
port
:
5432
,
user
:
'
user
'
,
searchPath
:
'
path
'
,
}
new
Client
(
params
)
const
{
dbtype
:
client
,
...
connection
}
=
params
const
knexConfig
:
Knex
.
Config
=
{
client
,
connection
}
expect
(
knex
).
toHaveBeenCalledWith
(
knexConfig
)
})
})
src/client/client.ts
0 → 100644
View file @
dbfb9d43
import
knex
from
'
knex
'
import
schemaInspector
from
'
knex-schema-inspector
'
export
type
SupportedDialects
=
'
pg
'
|
'
mysql
'
|
'
sqlite3
'
|
'
oracledb
'
|
'
mssql
'
export
interface
ClientParams
{
dbtype
:
SupportedDialects
host
:
string
port
:
number
user
:
string
password
:
string
database
:
string
searchPath
?:
string
}
/**
* The SQL client
*
*/
export
default
class
Client
{
protected
dbClient
protected
inspector
protected
tables
?:
string
[]
constructor
(
params
:
ClientParams
)
{
const
{
dbtype
,
...
connection
}
=
params
this
.
dbClient
=
knex
({
client
:
dbtype
,
connection
,
})
this
.
inspector
=
schemaInspector
(
this
.
dbClient
)
}
async
loadMetadata
()
{
this
.
loadTablesMetadata
()
}
private
async
loadTablesMetadata
()
{
this
.
tables
=
await
this
.
inspector
.
tables
()
}
}
src/main.ts
View file @
dbfb9d43
import
{
getCli
}
from
"
./cli/yargs
"
import
{
getCli
}
from
'
./cli/yargs
'
import
Client
from
'
./client/client
'
import
type
{
SupportedDialects
}
from
'
./client/client
'
const
args
=
getCli
()
const
client
=
new
Client
({
database
:
args
.
dbname
,
dbtype
:
args
.
dbtype
as
SupportedDialects
,
host
:
args
.
hostname
,
password
:
args
.
password
,
port
:
args
.
port
,
user
:
args
.
user
,
searchPath
:
args
.
schemaname
,
})
/**
*
*
* @param {string} string
*/
function
test
(
string
:
string
)
{
console
.
log
(
string
)
}
console
.
log
(
getCli
())
console
.
log
(
'
test
'
)
console
.
log
(
'
abc
'
)
console
.
log
(
client
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment