-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 | ||
} | ||
*/ |