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

wait for postgres, possibly fixes https://github.com/matrix-discord/mx-puppet-discord/issues/78 #64

Open
wants to merge 3 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
4 changes: 3 additions & 1 deletion src/db/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export class Postgres implements IDatabaseConnector {
constructor(private connectionString: string) {

}
public Open() {
public async Open(): Promise<void> {
// Hide username:password
const logConnString = this.connectionString.substr(
this.connectionString.indexOf("@") || 0,
);
log.info(`Opening ${logConnString}`);
this.db = pgp(this.connectionString);
// Wait for postgres to be ready by returning a promise for a connection
return this.db.connect();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this return to await fixes the compilation error:

Suggested change
return this.db.connect();
await this.db.connect();

}

public async Get(sql: string, parameters?: ISqlCommandParameters): Promise<ISqlRow|null> {
Expand Down
2 changes: 1 addition & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class Store {
this.db = new SQLite3(this.config.filename);
}
try {
this.db.Open();
await Promise.resolve(this.db.Open());
this.pRoomStore = new DbRoomStore(this.db);
this.pUserStore = new DbUserStore(this.db);
this.pGroupStore = new DbGroupStore(this.db);
Expand Down