{"id":19789585,"url":"https://github.com/webfreak001/mongoschemad","last_synced_at":"2025-05-01T01:31:44.197Z","repository":{"id":146627882,"uuid":"45578199","full_name":"WebFreak001/MongoSchemaD","owner":"WebFreak001","description":"Support for more structured MongoDB databases","archived":false,"fork":false,"pushed_at":"2024-04-02T11:22:48.000Z","size":87,"stargazers_count":9,"open_issues_count":2,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-02T05:12:08.237Z","etag":null,"topics":["bson","d","database","library","mongodb","schemas","templates"],"latest_commit_sha":null,"homepage":null,"language":"D","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/WebFreak001.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,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-11-05T01:09:39.000Z","updated_at":"2021-10-16T08:14:20.000Z","dependencies_parsed_at":"2024-02-05T17:42:13.503Z","dependency_job_id":null,"html_url":"https://github.com/WebFreak001/MongoSchemaD","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebFreak001%2FMongoSchemaD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebFreak001%2FMongoSchemaD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebFreak001%2FMongoSchemaD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebFreak001%2FMongoSchemaD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebFreak001","download_url":"https://codeload.github.com/WebFreak001/MongoSchemaD/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224231420,"owners_count":17277386,"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":["bson","d","database","library","mongodb","schemas","templates"],"created_at":"2024-11-12T06:34:00.656Z","updated_at":"2024-11-12T06:34:01.082Z","avatar_url":"https://github.com/WebFreak001.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoSchemaD\n\nA simple library for vibe.d adding support for structured Bson\ndata using structs/classes and functions to simplify saving,\nupdating and finding Mongo documents.\n\nCan also be used without MongoDB for Bson (de)serialization.\n\n## Example\n\n```d\nimport vibe.db.mongo.mongo;\nimport mongoschema;\nimport mongoschema.aliases : name, ignore, unique, binary;\n\nstruct Permission\n{\n\tstring name;\n\tint priority;\n}\n\nstruct User\n{\n\tmixin MongoSchema; // Adds save, update, etc.\n\n\t@unique\n\tstring username;\n\n\t@binary()\n\tubyte[] hash;\n\t@binary()\n\tubyte[] salt;\n\n\t@name(\"profile-picture\")\n\tstring profilePicture = \"default.png\";\n\n\tPermission[] permissions;\n\n\t@ignore:\n\tint sessionID;\n}\n\n// implement these for this example\n// if you use static arrays in the functions (like using the std.digest methods)\n// you need to call .idup on your arrays to copy them to GC memory, otherwise\n// they would corrupt when leaving the stack frame. (returning the function)\nubyte[] generateSalt();\nubyte[] complicatedHashFunction();\n\nUser registerNewUser(string name, string password)\n{\n\tUser user;\n\tuser.username = name;\n\tuser.salt = generateSalt();\n\tuser.hash = complicatedHashFunction(password, user.salt);\n\tuser.permissions ~= Permission(\"forum.access\", 1);\n\t// Automatically serializes and puts the object in the registered database\n\t// If save was already called or the object got retrieved from the\n\t// collection `save()` will just update the existing object.\n\tuser.save();\n\t// -\u003e\n\t// {\n\t//   username: name,\n\t//   hash: \u003cbinary\u003e,\n\t//   salt: \u003cbinary\u003e,\n\t//   profile-picture: \"default.png\",\n\t//   permissions: [{\n\t//     name: \"forum.access\",\n\t//     priority: 1\n\t//   }]\n\t// }\n\treturn user;\n}\n\n// convenience method, could also put this in the User struct\nUser find(string name)\n{\n\t// throws if not found, can also use `tryFindOne` to get a Nullable instead\n\t// of throwing an exception.\n\treturn User.findOne([\"username\": name]);\n}\n\nvoid main()\n{\n\t// connect as usual\n\tauto client = connectMongoDB(\"localhost\");\n\n\t// before accessing any MongoSchemaD functions on a struct, register the\n\t// structs using the `MongoCollection.register!T` function globally.\n\n\t// Links the `test.users` collection to the `User` struct.\n\tclient.getCollection(\"test.users\").register!User;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebfreak001%2Fmongoschemad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebfreak001%2Fmongoschemad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebfreak001%2Fmongoschemad/lists"}