db-scout
Version:
get database information, generate migration files, create models based on information
19 lines (18 loc) • 672 B
JavaScript
export class ParseUrl {
constructor(dbUrl) {
this.parsedUrl = new URL(dbUrl);
}
getParsedUrl() {
return {
user: this.parsedUrl.username,
password: this.parsedUrl.password,
host: this.parsedUrl.hostname,
port: parseInt(this.parsedUrl.port),
database: this.parsedUrl.pathname.substring(1),
ssl: this.parsedUrl.searchParams.has('sslmode')
? this.parsedUrl.searchParams.get('sslmode') || 'disable'
: 'disable',
schema: this.parsedUrl.searchParams.has('schema') ? this.parsedUrl.searchParams.get('schema') : null,
};
}
}