Skip to content

Instantly share code, notes, and snippets.

@kino6052
Last active December 25, 2021 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kino6052/9444a8e7f6fe45410425188275807996 to your computer and use it in GitHub Desktop.
Save kino6052/9444a8e7f6fe45410425188275807996 to your computer and use it in GitHub Desktop.
TSQL
// 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;
};
}
// 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: []
}
// Reusable fragments done with the spread operator
const fragment: IHero = {
name: '',
appearsIn: [],
friends: []
}
const comparison = {
leftComparison: {
episode: 'Empire',
...fragment
},
rightComparison: {
eposode: 'Jedi',
...fragment
}
}
// Example of conditional "directive" using a variable
const shouldIncludeFriends = false;
const heroWithQuery: IHero = {
name: "",
appearsIn: [],
...(!!shouldIncludeFriends && {
friends: [],
}),
};
// 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