Skip to content

Commit

Permalink
Do not compile test folder
Browse files Browse the repository at this point in the history
  • Loading branch information
codemicah committed Aug 26, 2023
1 parent 84d1eeb commit 1b86ecd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/config/database.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Pool, QueryConfig } from "pg";
import { Pool, PoolClient, QueryConfig } from "pg";
import { config } from "./env";
import { userSchema } from "../models/user";
import { postSchema } from "../models/post";
Expand All @@ -19,13 +19,8 @@ pool.on("error", (err, _client) => {
process.exit(-1);
});

pool.on("connect", (client) => {
// create Users table
client.query(userSchema);
// create Posts table
client.query(postSchema);
// create Comments table
client.query(commentSchema);
pool.on("connect", async (client) => {
await setUpSchemas(client);
});

// function to facilitate queries
Expand All @@ -34,4 +29,23 @@ const dbQuery = async (query: QueryConfig) => {
return response.rows;
};

async function setUpSchemas(client: PoolClient) {
// create Users table
client.query(userSchema);
// create Posts table
client.query(postSchema);
// create Comments table
client.query(commentSchema);
// create indexes
client.query({
text: `CREATE INDEX IF NOT EXISTS idx_total_posts ON Users (totalPosts)`,
});
client.query({
text: `CREATE INDEX IF NOT EXISTS idx_post_author ON Posts (author)`,
});
client.query({
text: `CREATE INDEX IF NOT EXISTS idx_comment ON Comments (createdAt, userId, postId)`,
});
}

export default dbQuery;
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"strict": true /* Enable all strict type-checking options. */ /* Skip type checking .d.ts files that are included with TypeScript. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["src"]
"include": ["src"],
"exclude": ["src/tests"]
}

0 comments on commit 1b86ecd

Please sign in to comment.