MCPcopy
hub / github.com/dbcli/pgcli / change_db

Method change_db

pgcli/main.py:465–493  ·  view source on GitHub ↗
(self, pattern, **_)

Source from the content-addressed store, hash-verified

463 )
464
465 def change_db(self, pattern, **_):
466 if pattern:
467 # Get all the parameters in pattern, handling double quotes if any.
468 infos = re.findall(r'"[^"]*"|[^"\'\s]+', pattern)
469 # Now removing quotes.
470 [s.strip('"') for s in infos]
471
472 infos.extend([None] * (4 - len(infos)))
473 db, user, host, port = infos
474 try:
475 self.pgexecute.connect(
476 database=db,
477 user=user,
478 host=host,
479 port=port,
480 **self.pgexecute.extra_args,
481 )
482 except OperationalError as e:
483 click.secho(str(e), err=True, fg="red")
484 click.echo("Previous connection kept")
485 else:
486 self.pgexecute.connect()
487
488 yield (
489 None,
490 None,
491 None,
492 'You are now connected to database "%s" as user "%s"' % (self.pgexecute.dbname, self.pgexecute.user),
493 )
494
495 def execute_from_file(self, pattern, **_):
496 if not pattern:

Callers

nothing calls this directly

Calls 2

echoMethod · 0.80
connectMethod · 0.45

Tested by

no test coverage detected