Skip to content

Instantly share code, notes, and snippets.

View dipeshhkc's full-sized avatar
🏠
Working from home

Dipesh KC dipeshhkc

🏠
Working from home
View GitHub Profile
import firebase from "firebase/app";
import 'firebase/analytics';
const firebaseConfig = {
apiKey: '***************',
authDomain: '**************',
projectId: '**************',
storageBucket: '*******************',
messagingSenderId: '****************',
appId: '*******************',
//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 {
// 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()
//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)
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})
// 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()));"`
//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
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" />
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));
import Head from "next/head";
export default function Home() {
return (
<div>
<Head>
<title>
Social Media Preview
</title>
<meta property="og:url" content="your url" />