This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
postgres: | |
image: postgres:14.1-alpine | |
restart: always | |
environment: | |
# You can set the value of environment variables | |
# in your docker-compose.yml file | |
# Our Node app will use these to connect | |
# to the database | |
- POSTGRES_USER=root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create database | |
CREATE DATABASE "RENTALS"; | |
CREATE TABLE CUSTOMER ( | |
CID SERIAL PRIMARY KEY, | |
name TEXT NOT NULL, | |
address TEXT NOT NULL, | |
phone TEXT NOT NULL | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Defining a searchBy method on an array | |
interface SearchFn<T> { | |
(key: string, value: string): { index: number; value: T }[] | undefined; | |
} | |
// Extend the Array interface to include a searchBy method | |
interface SearchableArray<T> extends Array<T> { | |
searchBy: SearchFn<T>; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A utility method to safely extract environment variables. | |
* By default, if an environment variable is asked to be extracted but it is missing, this method will throw an error. | |
* @param options - Additional options for this method's behaviour, including deciding if it should throw when a variable is missing. | |
* @param environmentVariables - A spread of environment variable keys to be fetched from process.env. | |
* @returns A new object with each environmentVariables key in it. Unless throwOnError is false, all environmentVariables params will be present. | |
*/ | |
export const extract_environment_variables = <T extends string[]>( | |
{ throwOnError = true }: { throwOnError?: boolean }, | |
...environmentVariables: T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Type alias to recursively make all properties of an object optionally undefined or null. | |
* Adds | undefined | null to all objects and its properties. | |
*/ | |
type DeepNullable<T> = T extends object | |
? { [k in keyof T]?: DeepNullable<T[k] | null> } | |
: T | null; | |
interface TestObj { | |
nothing: boolean; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example of a higher-order component with type-safety for functions with generic spread variables. | |
* In this example, the HOC is a function to create AWS Lambda (for AWS API Gateway) function handlers. | |
* All AWS Lambda exported handlers receive an (event, context) set of parameters. | |
* | |
* @author Adrian Gabardo <[email protected]> | |
*/ | |
type LambdaResponse = Promise<any | void>; | |
type BaseLambda = (event, context) => LambdaResponse; |