pluja / pocketbase

PocketBase Go SDK
MIT License
50 stars 14 forks source link

Performing CRUD operations on the collections #7

Open nasoooor29 opened 2 months ago

nasoooor29 commented 2 months ago

Performing CRUD operations on the collections

by this i mean i can create the collection from my code i tried to search or figure it out on my own but i wasn't able to

refrence

  1. https://pocketbase.io/docs/api-collections/#create-collection
  2. https://pocketbase.io/docs/api-collections/#import-collections

solutions:

create a external tool

type MyCustomStruct struct { Name string Age int etc string Nested *NestedStruct } type NestedStruct struct { AnotherField string }

func SetupDB(client *pocketbase.Client) error { val := MyCustomStruct{ Name: "", Age: 0, etc: "", Nested: &NestedStruct{ AnotherField: "", }, } res, err := client.CreateCollection("MyCustomCollection", val) if err != nil ...

}



# Additional
i made a tool that make similar json to the generated one from pocket base on this repo
https://github.com/nasoooor29/PocketBaseSDKThing
nasoooor29 commented 2 months ago

i think the relation type may cause a headace for us if we want to infer it to go code, for me i reached this conclusion if the type is not a struct or map and it's a pointer we throw an error if it's one of the known concreate types we just parse them if it was a struct (not pointer to struct) we take the fields and add them to the parent example:

// input: 
type MyCustomStruct struct {
    Name  string
    Age   int
    inner MyInnerStruct
}

type MyInnerStruct struct {
    InnerName string
    InnerAge  int
}

// output:
type ResultStruct struct {
    Name  string
    Age   int
    InnerName string
    InnerAge  int
}

when i typed it i think we should not do this idea and just throw an error if there is an inner struct (not pointer to struct) because we won't be able to destructure the again when we retrive the data into the 2 or more nested structs

so im leaning into making a new collection for each struct or struct ptr

nasoooor29 commented 2 months ago

@pluja i have done a small prototype you can check it on this repo it almost works by generating the json there is only some remaining types, can you check it and tell me if i can continue or you can take the code to continue the implementation.

https://github.com/nasoooor29/PocketBaseSDKThing