Skip to content

Instantly share code, notes, and snippets.

@vegadelalyra
Created August 27, 2023 07:49
Show Gist options
  • Save vegadelalyra/07a22f864de7cc484c5e06535c803272 to your computer and use it in GitHub Desktop.
Save vegadelalyra/07a22f864de7cc484c5e06535c803272 to your computer and use it in GitHub Desktop.
Explaining SQL DB with TS classes
class Pets {
private name: string
private age: number
private sound: string
private type: string
constructor(name: string, age: number, sound: string = 'wow', type: string) {
this.name = name;
this.age = age;
this.sound = sound;
this.type = type;
}
sayName() {
return console.log('Your', this.type, 'is called', this.name)
}
howOld() {
return console.log(this.name, 'is', this.age, 'years old c:')
}
greet() {
return console.log(this.name, 'does', this.sound, '<3')
}
whoIs() {
return console.log(this.name, 'is a beautiful', this.type + '!')
}
}
const Tommy = new Pets('Tommy', 6, undefined, 'doggie')
Tommy.sayName()
Tommy.greet()
Tommy.howOld()
Tommy.whoIs()
@vegadelalyra
Copy link
Author

A scheme is based on cumulative and mixable entities composited by attributes with constraints that form an idea or witticism of the entity.

Equally, a SQL DB is based on related indexed and normalized tables composited by columns with constraints on type and value that form an instance of the table.

This concept can be abstracted to the classes on languages compatible with the so called "object oriented programming" as TypeScript, whereas our schema or relational database called module has this entity or table or class token called Pets that carries some attributes, columns or constructor methods which have to follow an interface declared in the enclosing class or at the beginning of the class by its type or encapsulation, so they carry constraints and if you follow them when invoking a new object from the class you're not only creating a brand new instance of the class but also of your entity or les't say, your relational data base.

SQL DB CONCEPTS

Just a little abstraction and free-license literal I borrow to teach easily the SQL db concept to my students. Apologies, by any means.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment