Posts

Showing posts from April, 2024

week 10.2 prisma

Image
//using ORM : Simpler syntax (converts objects to SQL queries under the hood) //code CREATE TABLE users (     id SERIAL PRIMARY KEY,     name VARCHAR(100),     email VARCHAR(100) UNIQUE NOT NULL ); ALTER TABLE users ADD COLUMN phone_number VARCHAR(15);   //As your app grows, you will have a lot of these CREATE and ALTER commands. ORMs (or more specifically Prisma) maintains all of these for you. For example - https://github.com/code100x/cms/tree/main/prisma/migrations fd     //Data mode in prisma 1. Data model In a single file, define your schema. What it looks like, what tables you have, what field each table has, how are rows related to each other. 2. Automated migrations Prisma generates and runs database migrations based on changes to the Prisma schema. 3. Type Safety Prisma generates a type-safe database client based on the Prisma schema. 4. Auto-Completion       //installing prisima lets create simple t...

week 10.1, postgraceSQL, creating table in database

// initialise an empty typescript project npm init -y npx tsc --init -:  change the rootDir and outDir in tscongig.json instll pf libarary and it's type (because we're usign TS) npm install pg npm install @types/pg   Create a similar node.js app that lets you put data ======================================= //write a function to create a uses table in your databse. import  { Client } from 'pg' const client = new Client({ connectionString: ""  }) client.connect() //curd operations // write a function to create a uses table in your databse. import  { Client } from 'pg' const client = new Client ({ connectionString : "postgresql://test_owner:eSLcgdkBX9D1@ep-fragrant-boat-a56z1tgw.us-east-2.aws.neon.tech/test?sslmode=require"  })   async function createUsersTable () {     await client . connect () //create operation      const result = await client . query ( `     CREATE TABLE users (       ...

week 9.3, enum, generics, import, export, typescript.

//enum is another cleaner way to write  constant value enum direction { Up, Down, Left, Right } doSommthing(direction.up)  const app = express (); enum ResponseStatus {     Success = 200 ,     NotFond = 404 ,     Error = 500 } //200, 404,  500 app . get ( "/" , ( res , res ) => {     if (! req . query . userId ) {         res . status { ResponseStatus . NotFond }     }     //and so on     res . json ({}); }) app . get ( "/" , ( res , res ) => {     if (! req . query . userId ) {         res . status { ResponseStatus . NotFond }     }     //and so on     res . json ({}); }) //Generic // User can send different type of values in inputs, without any type errors. // Typescript isn't able to infer the right type of the return type // User can send different type of values in inputs, without any type errors. // Typ...

Typescript intro

Image
step 0. [Set-ExecutionPolicy RemoteSigned -Scope CurrentUser] // use this commend when you get message running scripts is disabled. first run power-shell as a administrator.     step1 install tsc/typescript globally  npm install -g typescript //after installation initialize an empty node.js project with typescript :- mkdir fileName :- cd fileName step2 intialize a empty node.js project with typescripts npm init -y  npx tsc --init step3 create a a.ts file const x: number = 1; console.log(x); step4 compile the ts file to js file  tsc -b   difference between type scripts and Javascript typescript is strongly  js is loosely //in typeScript const x : number = 20 ; console . log ( x ); //in javaScript /* const x = 20; console.log(x); */   //write hello world in typescript      // write a function to calculate sum  of two number function val ( a : number , b : number ) {     return a + b ; } let sum = val ( 4 , 5 )...

6.2 week React, axios, paging, useMemo, memo, react-core-concept, consom-hooks

//side effect*  // side effect in React, the concept of side effects encompasses any operations that reach outside the functional scope of a React component. These operations can affect other components, interact with the browser, or perform asynchronous data fetching. //useState is a React Hook that lets you add a state variable to your component . const [state, setState] = useState(initialState) useState(initialState) set functions, like setSomething(nextState)  //UseEffect**    import { useEffect, useState } from 'react' import './App.css' import axios from "axios"; function App() {   const [todos, setTodos] = useState([]);   useEffect(() => {     axios.get("https://sum-server.100xdevs.com/todos")     .then(function (response) {       setTodos(response.data.todos)     })   }, []);   return (     <>     {todos.map(todo => <Todo k...