Skip to content

Commit

Permalink
Added Save func for post
Browse files Browse the repository at this point in the history
  • Loading branch information
SariaAlam committed Oct 18, 2023
1 parent c6f5d4b commit 3c162c4
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions internal/model/post.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package model

import (
"github.com/SohelAhmedJoni/Awazz-Backend/internal/durable"
)

func (p *Post) SavePost() error {
db, err := durable.CreateDatabase("Database/post.sqlite")
if err != nil {
panic(err)
}
defer db.Close()
str := `
CREATE TABLE IF NOT EXISTS Post (
Id VARCHAR(128) PRIMARY KEY,
Community VARCHAR(128),
Content TEXT,
CreatedAt TIMESTAMP,
UpdatedAt TIMESTAMP,
DeletedAt TIMESTAMP,
Likes INT,
Shares INT,
Comments INT,
Author VARCHAR(128),
Parent INT,
Rank INT,
Children VARCHAR(128),
Tags VARCHAR(128),
Mentions VARCHAR(128),
IsSensitive bool,
IsNsfw bool,
IsDeleted bool,
IsPinned bool,
IsEdited bool,
IsLiked bool,
IsShared bool,
IsCommented bool,
IsSubscribed bool,
IsBookmarked bool,
IsReblogged bool,
IsMentioned bool,
IsPoll bool,
IsPollVoted bool,
IsPollExpired bool,
IsPollClosed bool,
IsPollMultiple bool,
IsPollHideTotals bool)
`
_, err = db.Exec(str)
if err != nil {
panic(err)
}
str2 := `
INSERT INTO Post (Id,Community,Content,CreatedAt,UpdatedAt,DeletedAt,Likes,Shares,Comments,Author,Parent,Rank,Children,Tags,Mentions,IsSensitive,IsNsfw,IsDeleted,IsPinned,IsEdited,IsLiked,IsShared,IsCommented,IsSubscribed,IsBookmarked,IsReblogged,IsMentioned,IsPoll,IsPollVoted,IsPollExpired,IsPollClosed,IsPollMultiple,IsPollHideTotals) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);
`
statement, err := db.Prepare(str2)
if err != nil {
panic(err)
}
_, err = statement.Exec(p.Id,
p.Community,
p.Content,
p.CreatedAt.String(),
p.UpdatedAt.String(),
p.DeletedAt.String(),
p.Likes,
p.Shares,
p.Comments,
p.Author,
p.Parent,
p.Rank,
p.Children[0],
p.Tags[0],
p.Mentions[0],
p.IsSensitive,
p.IsNsfw,
p.IsDeleted,
p.IsPinned,
p.IsEdited,
p.IsLiked,
p.IsShared,
p.IsCommented,
p.IsSubscribed,
p.IsBookmarked,
p.IsReblogged,
p.IsMentioned,
p.IsPoll,
p.IsPollVoted,
p.IsPollExpired,
p.IsPollClosed,
p.IsPollMultiple,
p.IsPollHideTotals,
p.IsPollHideTotals
)
if err != nil {
panic(err)
}

return nil
}

/*func (p *Post) GetPost() error {
db,
err := durable.CreateDatabase("Database/post")
if err != nil {
panic(err)
}
defer db.Close()
return nil
}
func (p *Post) UpdatePost() error {
db, err := durable.CreateDatabase("Database/Post")
if err != nil {
panic(err)
}
defer db.Close()
return nil
}
func (p *Post) DeletePost() error {
db, err := durable.CreateDatabase("Database/Post")
if err != nil {
panic(err)
}
defer db.Close()
return nil
}
*/

0 comments on commit 3c162c4

Please sign in to comment.