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
import firebase from "firebase/app"; | |
import 'firebase/analytics'; | |
const firebaseConfig = { | |
apiKey: '***************', | |
authDomain: '**************', | |
projectId: '**************', | |
storageBucket: '*******************', | |
messagingSenderId: '****************', | |
appId: '*******************', |
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 New POST | |
post := &Post{Name: "Post2"} | |
if db.Create(&post).Error != nil { | |
log.Panic("Unable to create post") | |
} | |
//RELATION QUERY (POST & COMMENT) | |
comment := &Comment{Name: "Nice Post", PostID: post.ID} | |
if db.Create(&comment).Error != nil { |
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
// Post is the model for the posts table. | |
type Post struct { | |
ID MYTYPE `gorm:"primary_key;"` | |
Name string `gorm:"not null"` | |
Comment Comment | |
} | |
// BeforeCreate -> | |
func (p *Post) BeforeCreate(tx *gorm.DB) error { | |
id, err := uuid.NewRandom() |
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
//ADDING NEW POST | |
post := &Post{Name: "My First Post"} | |
if db.Create(&post).Error != nil { | |
log.Panic("Unable to create post") | |
} | |
log.Print("just created post",post.ID) | |
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
USER := "root" | |
PASS := "root" | |
HOST := "localhost" | |
PORT := "3306" | |
DBNAME := "test" | |
url := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", USER, PASS, HOST, PORT, DBNAME) | |
db, err := gorm.Open(mysql.Open(url), &gorm.Config{Logger: newLogger}) | |
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
// Post is the model for the posts table. | |
type Post struct { | |
ID MYTYPE `gorm:"primary_key;default:(UUID_TO_BIN(UUID()));"` | |
Name string `gorm:"not null"` | |
Comment Comment | |
} | |
// Comment is the model for the comments table. | |
type Comment struct { | |
ID MYTYPE `gorm:"primary_key;default:(UUID_TO_BIN(UUID()));"` |
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
//MYTYPE -> new datatype | |
type MYTYPE uuid.UUID | |
// StringToMYTYPE -> parse string to MYTYPE | |
func StringToMYTYPE(s string) (MYTYPE, error) { | |
id, err := uuid.Parse(s) | |
return MYTYPE(id), err | |
} | |
//String -> String Representation of Binary16 |
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
import Head from 'next/head'; | |
import React from 'react'; | |
const Home=({photo})=> { | |
return ( | |
<div> | |
<Head> | |
<title>Social Media Preview</title> | |
<meta property="og:url" content="your url" /> |
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
import Head from 'next/head'; | |
import React,{useState,useEffect} from "react" | |
export default function Home() { | |
const [photo, setPhoto] = useState(); | |
useEffect(() => { | |
fetch('https://jsonplaceholder.typicode.com/photos/1') | |
.then((response) => response.json()) | |
.then((json) => setPhoto(json)); |
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
import Head from "next/head"; | |
export default function Home() { | |
return ( | |
<div> | |
<Head> | |
<title> | |
Social Media Preview | |
</title> | |
<meta property="og:url" content="your url" /> |