Skip to content

Commit

Permalink
"Add SavePerson method to Person model"
Browse files Browse the repository at this point in the history
  • Loading branch information
JonyBepary committed Oct 18, 2023
1 parent 99e56bb commit c6f5d4b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions internal/model/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

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

var column []string = []string{
Expand Down Expand Up @@ -43,7 +44,7 @@ var column_type []string = []string{
"TEXT",
"TEXT",
"TEXT",
"NUMERIC",
"TEXT",
"TEXT",
"BLOB",
"BLOB",
Expand All @@ -52,7 +53,7 @@ var column_type []string = []string{
"TEXT",
"TEXT",
"TEXT",
"NUMERIC",
"TEXT",
"TEXT",
"TEXT",
"TEXT",
Expand All @@ -70,12 +71,23 @@ var column_type []string = []string{
"BLOB"}

func (p *Person) SavePerson() error {
db, err := durable.CreateDatabase("Database/comments")
db, err := durable.CreateDatabase("./Database/persons.sqlite")
if err != nil {
return err
}
defer db.Close()
fmt.Printf("CREATE TABLE IF NOT EXISTS PERSON ( %v)\n", durable.SetColumn(column, column_type))
// db.Query(fmt.Sprintf("CREATE TABLE PERSON ( %v)", durable.SetColumn(column, column_type)))

_, err = db.Exec(fmt.Sprintf("CREATE TABLE IF NOT EXISTS PERSON ( %v)", durable.SetColumn(column, column_type)))
if err != nil {
return err
}
statement, err := db.Prepare("INSERT INTO PERSON (Id,AttributedTo,Context,MediaType,EndTime,Generator,InReplyTo,Location,Preview,Published,Replies,StartTime,Summary,Tag,Updated,Url,Likes,Shares,Inbox,Outbox,Following,Followers,Liked,PreferredUsername,Endpoints) VALUES (? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? ,? )")
if err != nil {
return err
}
_, err = statement.Exec(p.Id, pkg.ReadFile(p.Attachment), p.AttributedTo, p.Context, p.MediaType, p.EndTime.String(), p.Generator, pkg.ReadFile(p.Icon), pkg.ReadFile(p.Image), p.InReplyTo, p.Location, p.Preview, p.Published.String(), p.Replies, p.StartTime.String(), p.Summary, p.Tag[0], p.Updated.String(), p.Url, p.To[0], p.Bto[0], p.Cc[0], p.Bcc[0], p.Likes, p.Shares, p.Inbox, p.Outbox, p.Following, p.Followers, p.Liked, p.PreferredUsername, p.Endpoints, p.Streams[0], p.PublicKey)
if err != nil {
return err
}
return nil
}

0 comments on commit c6f5d4b

Please sign in to comment.