Last active
December 25, 2021 03:05
-
-
Save kino6052/9444a8e7f6fe45410425188275807996 to your computer and use it in GitHub Desktop.
TSQL
This file contains 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 how types could be declared using TS interfaces | |
interface IEpisode { | |
title: string; | |
} | |
interface ICharacter { | |
name: string; | |
appearsIn: IEpisode[]; | |
} | |
interface IHero extends ICharacter { | |
name: string; | |
friends: ICharacter[]; | |
} | |
interface IStarship { | |
id: string; | |
name: string; | |
length: { | |
unit: "METER" | "FOOT"; | |
value: number; | |
}; | |
} |
This file contains 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
// An example of querying first hero the DB returns | |
const firstHero: IHero = { | |
name: "", | |
appearsIn: [], | |
friends: [ | |
{ | |
name: "", | |
appearsIn: [], | |
}, | |
], | |
}; | |
// An example of getting all heros in the DB | |
const allHeroes: IHero[] = [ | |
{ | |
name: "", | |
appearsIn: [], | |
friends: [ | |
{ | |
name: "", | |
appearsIn: [], | |
}, | |
], | |
}, | |
]; | |
// An example of getting a more specific result | |
const firstHeroWithArguments: IHero = { | |
name: "Luke Skywalker", | |
appearsIn: [{ | |
title: 'Return of the Jedi' | |
}], | |
friends: [] | |
} | |
// An example of getting a result using regex | |
const firstHeroWithRegexArguments: IHero = { | |
name: "/^luke.*/i", | |
appearsIn: [{ | |
title: '/^return.*/i' | |
}], | |
friends: [] | |
} |
This file contains 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
// Reusable fragments done with the spread operator | |
const fragment: IHero = { | |
name: '', | |
appearsIn: [], | |
friends: [] | |
} | |
const comparison = { | |
leftComparison: { | |
episode: 'Empire', | |
...fragment | |
}, | |
rightComparison: { | |
eposode: 'Jedi', | |
...fragment | |
} | |
} |
This file contains 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 conditional "directive" using a variable | |
const shouldIncludeFriends = false; | |
const heroWithQuery: IHero = { | |
name: "", | |
appearsIn: [], | |
...(!!shouldIncludeFriends && { | |
friends: [], | |
}), | |
}; |
This file contains 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 querying API | |
// For reading | |
readEntity(heroWithQuery); | |
// For mutating | |
createEntity(heroWithQuery); | |
updateEntity(heroWithQuery); | |
deleteEntity(heroWIthQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment