commit 486d5ee30f57546a80c695632e52085c5f16560a Author: ☙◦ The Tablet ❀ GamerGirlandCo ◦❧ Date: Mon Jun 30 17:41:05 2025 -0400 hello again, universe~ 🌸 diff --git a/.dir-locals.el b/.dir-locals.el new file mode 100644 index 0000000..b8c0deb --- /dev/null +++ b/.dir-locals.el @@ -0,0 +1,3 @@ +((nil . ((elcord-project-name . "the diamond ORM") + (elcord-project-description . "a mongodb ORM for golang that rocks!") + ))) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0741d58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.exe +go.work.sum +go.work +muck/ +/build/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..7faf1ba --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..dd4c951 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..062a2a4 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..67ee188 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0d8a8dd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/orm.iml b/.idea/orm.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/orm.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..98358d8 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9092697 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nuxt.isNuxtApp": false +} \ No newline at end of file diff --git a/document.go b/document.go new file mode 100644 index 0000000..5800656 --- /dev/null +++ b/document.go @@ -0,0 +1 @@ +package orm diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6184ae1 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module rockfic.com/orm + +go 1.24.1 + +require ( + github.com/go-loremipsum/loremipsum v1.1.4 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.7.5 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/stretchr/testify v1.10.0 // indirect + golang.org/x/crypto v0.37.0 // indirect + golang.org/x/sync v0.13.0 // indirect + golang.org/x/text v0.24.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..02a5257 --- /dev/null +++ b/go.sum @@ -0,0 +1,25 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-loremipsum/loremipsum v1.1.4 h1:RJaJlJwX4y9A2+CMgKIyPcjuFHFKTmaNMhxbL+sI6Vg= +github.com/go-loremipsum/loremipsum v1.1.4/go.mod h1:whNWskGoefTakPnCu2CO23v5Y7RwiG4LMOEtTDaBeOY= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs= +github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/testing.go b/testing.go new file mode 100644 index 0000000..67f9e69 --- /dev/null +++ b/testing.go @@ -0,0 +1,254 @@ +package orm + +import ( + "context" + "fmt" + "github.com/stretchr/testify/assert" + "strings" + "testing" + "time" + + "github.com/go-loremipsum/loremipsum" +) + +type chapter struct { + ID bson.ObjectID `json:"_id"` + Title string `json:"chapterTitle" form:"chapterTitle"` + ChapterID int `json:"chapterID" autoinc:"chapters"` + Index int `json:"index" form:"index"` + Words int `json:"words"` + Notes string `json:"notes" form:"notes"` + Genre []string `json:"genre" form:"genre"` + Bands []band `json:"bands" ref:"band,bands"` + Characters []string `json:"characters" form:"characters"` + Relationships [][]string `json:"relationships" form:"relationships"` + Adult bool `json:"adult" form:"adult"` + Summary string `json:"summary" form:"summary"` + Hidden bool `json:"hidden" form:"hidden"` + LoggedInOnly bool `json:"loggedInOnly" form:"loggedInOnly"` + Posted time.Time `json:"datePosted"` + FileName string `json:"fileName"` + Text string `json:"text" gridfs:"story_text,/stories/{{.ChapterID}}.txt"` +} + +type band struct { + ID int64 `json:"_id"` + Document `json:",inline" coll:"bands"` + Name string `json:"name" form:"name"` + Locked bool `json:"locked" form:"locked"` + Characters []string `json:"characters" form:"characters"` +} +type user struct { + ID int64 `json:"_id"` + Document `json:",inline" coll:"users"` + Username string `json:"username"` + Favs []user `json:"favs" ref:"user"` +} +type story struct { + ID int64 `json:"_id"` + Document `json:",inline" coll:"stories"` + Title string `json:"title" form:"title"` + Author *user `json:"author" ref:"user"` + CoAuthor *user `json:"coAuthor" ref:"user"` + Chapters []chapter `json:"chapters"` + Recs int `json:"recs"` + Favs int `json:"favs"` + Views int `json:"views"` + Completed bool `json:"completed" form:"completed"` + Downloads int `json:"downloads"` +} +type somethingWithNestedChapters struct { + ID int64 `json:"_id"` + Document `json:",inline" coll:"nested_stuff"` + Chapters []chapter `json:"chapters"` + NestedText string `json:"text" gridfs:"nested_text,/nested/{{.ID}}.txt"` +} + +func (s *somethingWithNestedChapters) Id() any { + return s.ID +} + +func (s *somethingWithNestedChapters) SetId(id any) { + s.ID = id.(int64) +} + +func (s *story) Id() any { + return s.ID +} + +func (s *band) Id() any { + return s.ID +} +func (s *user) Id() any { + return s.ID +} + +func (s *story) SetId(id any) { + s.ID = id.(int64) + //var t IDocument =s +} + +func (s *band) SetId(id any) { + s.ID = id.(int64) +} + +func (s *user) SetId(id any) { + s.ID = id.(int64) +} + +var author = user{ + Username: "tablet.exe", + Favs: []user{ + { + Username: "DarQuiel7", + }, + }, +} + +func genChaps(single bool) []chapter { + var ret []chapter + var ceil int + if single { + ceil = 1 + } else { + ceil = 5 + } + emptyRel := make([][]string, 0) + emptyRel = append(emptyRel, make([]string, 0)) + relMap := [][][]string{ + { + {"Sean Harris", "Brian Tatler"}, + }, + { + {"Sean Harris", "Brian Tatler"}, + {"Duncan Scott", "Colin Kimberley"}, + }, + { + {"Duncan Scott", "Colin Kimberley"}, + }, + emptyRel, + { + {"Sean Harris", "Colin Kimberley", "Brian Tatler"}, + }, + } + l := loremipsum.New() + + for i := 0; i < ceil; i++ { + spf := fmt.Sprintf("%d.md", i+1) + ret = append(ret, chapter{ + ID: bson.NewObjectID(), + Title: fmt.Sprintf("-%d-", i+1), + Index: i + 1, + Words: 50, + Notes: "notenotenote !!!", + Genre: []string{"Slash"}, + Bands: []band{diamondHead}, + Characters: []string{"Sean Harris", "Brian Tatler", "Duncan Scott", "Colin Kimberley"}, + Relationships: relMap[i], + Adult: true, + Summary: l.Paragraph(), + Hidden: false, + LoggedInOnly: true, + FileName: spf, + Text: strings.Join(l.ParagraphList(10), "\n\n"), + }) + } + + return ret +} + +func doSomethingWithNested() somethingWithNestedChapters { + l := loremipsum.New() + swnc := somethingWithNestedChapters{ + Chapters: genChaps(false), + NestedText: strings.Join(l.ParagraphList(15), "\n\n"), + } + return swnc +} +func iti_single() story { + return story{ + Title: "title", + Completed: true, + Chapters: genChaps(true), + } +} + +func iti_multi() story { + return story{ + Title: "Brian Tatler Fucked and Abused Sean Harris", + Completed: false, + Chapters: genChaps(false), + } +} + +func iti_blank() story { + t := iti_single() + t.Chapters = make([]chapter, 0) + return t +} + +func initTest() { + uri := "mongodb://127.0.0.1:27017" + db := "rockfic_ormTest" + ic, _ := mongo.Connect(options.Client().ApplyURI(uri)) + ic.Database(db).Drop(context.TODO()) + colls, _ := ic.Database(db).ListCollectionNames(context.TODO(), bson.M{}) + if len(colls) < 1 { + mdb := ic.Database(db) + mdb.CreateCollection(context.TODO(), "bands") + mdb.CreateCollection(context.TODO(), "stories") + mdb.CreateCollection(context.TODO(), "users") + } + defer ic.Disconnect(context.TODO()) + Connect(uri, db) + author.ID = 696969 + ModelRegistry.Model(band{}, user{}, story{}) +} + +var metallica = band{ + ID: 1, + Name: "Metallica", + Characters: []string{ + "James Hetfield", + "Lars Ulrich", + "Kirk Hammett", + "Cliff Burton", + }, + Locked: false, +} + +var diamondHead = band{ + ID: 503, + Name: "Diamond Head", + Locked: false, + Characters: []string{ + "Brian Tatler", + "Sean Harris", + "Duncan Scott", + "Colin Kimberley", + }, +} +var bodom = band{ + ID: 74, + Name: "Children of Bodom", + Locked: false, + Characters: []string{ + "Janne Wirman", + "Alexi Laiho", + "Jaska Raatikainen", + "Henkka T. Blacksmith", + "Roope Latvala", + "Daniel Freyberg", + "Alexander Kuoppala", + }, +} + +func saveDoc(t *testing.T, doc IDocument) { + err := doc.Save() + assert.Nil(t, err) +} + +func createAndSave(t *testing.T, doc IDocument) { + mdl := Create(doc).(IDocument) + saveDoc(t, mdl) +}