{"id":23159060,"url":"https://github.com/classfunc/cffirestore","last_synced_at":"2025-04-04T18:41:55.510Z","repository":{"id":212029394,"uuid":"730532867","full_name":"ClassFunc/cffirestore","owner":"ClassFunc","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-12T06:17:30.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-10T03:47:34.897Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ClassFunc.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-12-12T06:07:30.000Z","updated_at":"2023-12-12T06:08:56.000Z","dependencies_parsed_at":"2023-12-12T07:25:10.340Z","dependency_job_id":"afc7a226-77fe-4e18-a3da-e7c0bb544fa5","html_url":"https://github.com/ClassFunc/cffirestore","commit_stats":null,"previous_names":["classfunc/cffirestore"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClassFunc%2Fcffirestore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClassFunc%2Fcffirestore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClassFunc%2Fcffirestore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClassFunc%2Fcffirestore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClassFunc","download_url":"https://codeload.github.com/ClassFunc/cffirestore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234844,"owners_count":20905852,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-17T22:28:52.272Z","updated_at":"2025-04-04T18:41:55.491Z","avatar_url":"https://github.com/ClassFunc.png","language":"Go","readme":"## CFFIRESTORE\n\nHelpers for Firestore\n\n### Installation\n\n```bash\ngo get github.com/classfunc/cffirestore\n```\n\n### Usage\n\n```go\npackage main\n\nimport (\n\t\"github.com/classfunc/cffirestore\"\n)\n\nfunc main() {\n\t// Initialize a Firestore client\n\t// firebaseApp *firebase.App\n\t// fsClient *firestore.Client\n\t\n\tfsClient := firebaseApp.Firestore(context.Background())\n\tmyCollection := cffirestore.CollectionWithPath(fsClient, \"myCollection\")\n\t\n\t// add doc\n\tmyCollection.AddDocData(map[string]any{\"name\": \"John Doe\"})\n\t\n\t// list docs\n\tdocs, err := myCollection.ListDocs([]any{[]any{\"name\", \"==\", \"John Doe\"}})\n\t\n\t// check exists\n\texists, err := myCollection.CheckExists([]any{\n\t\t[]any{\"deletedAt\", \"==\", nil},\n\t\t[]any{\"name\", \"==\", \"John Doe\"},\n\t})\n\t\n\t//paginate\n\t// query /?perPage=3\u0026page=1\u0026sort=createdAt:desc\n\tvar q cffirestore.PaginateQueryParams\n\t//var ctx *gin.Context\n\t_ = ctx.BindQuery(\u0026q)\n\tkeys, err := myCollection.PaginateWithCount([]any{\n\t\t[]any{\"deletedAt\", \"==\", nil},\n\t\t[]any{\"uid\", \"==\", \"abc\"},\n\t\tmap[string]any{\n\t\t\t\"orderBy\": q.Sort,\n\t\t},\n\t}, q.Page, q.PerPage)\n}\n\n```\n\n#### ICFFSCollection Interface\nThe ICFFSCollection interface in Go provides a set of methods for interacting with a database collection. This abstraction is great because it allows your code to be decoupled from a specific implementation of accessing a database collection.\n```go\ntype ICFFSCollection interface {\n\tRef() *firestore.CollectionRef\n\tAddDocData(v map[string]any, docIdPrefix ...string) (*firestore.DocumentRef, *firestore.WriteResult, error)\n\tAddDoc(uid *string, v map[string]any, docIdPrefix ...string) (*firestore.DocumentRef, *firestore.WriteResult, error)\n\tAddDocWithId(id *string, uid *string, v map[string]any) (*firestore.DocumentRef, *firestore.WriteResult, error)\n\tListDocs(condition []any) ([]map[string]any, error)\n\tFindDoc(condition []any) (map[string]any, error)\n\tGetDoc(id string) (map[string]any, error)\n\tUpdateDoc(id string, data map[string]any) (*firestore.WriteResult, error)\n\tDeleteDoc(id string, isSoftDelete ...bool) (*firestore.WriteResult, error)\n\tDeleteDocs(condition []any, isSoftDelete ...bool) ([]*firestore.WriteResult, error)\n\tMakeQuery(condition []any) firestore.Query\n\tCountDocs(condition []any) (int, error)\n\tPaginate(condition []any, page int, perPage int) (map[string]any, error)\n\tPaginateWithCount(condition []any, page int, perPage int) (map[string]any, error)\n\tBatchDocs(condition []any, batchFn func(map[string]any) map[string]any) ([]*firestore.WriteResult, error)\n\tCheckExists(condition []any) (bool, error)\n}\n```\n\n#### Method descriptions\n- Ref(): returns a reference to the Firestore collection.\n- AddDocData(v, docIdPrefix): adds a document to the collection with optional docIdPrefix.\n- AddDoc(uid, v, docIdPrefix): adds a document to the collection under a user ID uid, an optional docIdPrefix can also be provided.\n- AddDocWithId(id, uid, v): adds a document to the collection with a specific document id and user uid.\n- ListDocs(condition): takes an array condition and lists all documents that meet the condition in the database collection.\n- FindDoc(condition): takes an array condition and returns the first document that meets the condition.\n- GetDoc(id): takes a document id and returns the document with given id.\n- UpdateDoc(id, data): takes a document id and data mapping, updates the document with the provided data.\n- DeleteDoc(id, isSoftDelete): deletes a document with optional soft delete.\n- DeleteDocs(condition, isSoftDelete): deletes documents that meet the condition with optional soft delete.\n- MakeQuery(condition): makes a database query according to condition.\n- CountDocs(condition): counts the number of documents that meet the condition.\n- Paginate(condition, page, perPage): paginates the document entries that meet the condition, each page contains perPage entries.\n- PaginateWithCount(condition, page, perPage): is similar to Paginate, but it also returns the total count of documents that meet the condition.\n- BatchDocs(condition, batchFn): takes a batch function batchFn and applies it to all documents that meet the condition.\n- CheckExists(condition): checks whether any document exists that meet the condition.\n\nNOTE: The condition parameter is an array which could be a composite condition based on more than one field of the documents in the database. \n\nThis interface is heavily dependent on Firestore's types and methods, a Firestore-specific implementation needs to be created for use. Any function that implements this interface can then interact with a Firestore database collection.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclassfunc%2Fcffirestore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclassfunc%2Fcffirestore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclassfunc%2Fcffirestore/lists"}