{"id":23806835,"url":"https://github.com/mattvb91/faunacrud","last_synced_at":"2025-09-06T17:31:18.108Z","repository":{"id":57233507,"uuid":"324118247","full_name":"mattvb91/FaunaCRUD","owner":"mattvb91","description":"Tiny CRUD model for FaunaDB","archived":false,"fork":false,"pushed_at":"2020-12-25T11:21:34.000Z","size":67,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-03T22:49:11.373Z","etag":null,"topics":["crud","crud-operation","faunadb","fql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mattvb91.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}},"created_at":"2020-12-24T09:29:23.000Z","updated_at":"2022-02-03T17:54:07.000Z","dependencies_parsed_at":"2022-08-31T14:11:31.613Z","dependency_job_id":null,"html_url":"https://github.com/mattvb91/FaunaCRUD","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FFaunaCRUD","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FFaunaCRUD/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FFaunaCRUD/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattvb91%2FFaunaCRUD/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattvb91","download_url":"https://codeload.github.com/mattvb91/FaunaCRUD/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232133902,"owners_count":18477299,"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":["crud","crud-operation","faunadb","fql"],"created_at":"2025-01-01T23:15:52.684Z","updated_at":"2025-01-01T23:15:53.250Z","avatar_url":"https://github.com/mattvb91.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# FaunaCRUD\n\nThis is more or less a \u003cb\u003eproof of concept\u003c/b\u003e playing around with typescript annotations to see if it was possible to come up with a tiny typed \"model\" to do some very basic CRUD operations to FaunaDB.\n\nAny attribute on your model that is annotated with `@FaunaData()` will be saved into your fauna document and parsed back out again when accessing it.\n\nIf you are looking for something more fleshed out your should check some of the following out:\n\n[faunadb-fql-lib](https://github.com/shiftx/faunadb-fql-lib)\n\n[biota](https://github.com/gahabeen/biota)\n\n[fauna_orm](https://github.com/graphflo/fauna_orm)\n\n\n### Getting started\n\n```bash\nyarn add fauna-crud\n\nnpm i fauna-crud\n```\n\nThis currently requires `FAUNA_SECRET` to be set in your runtime environment as your access key.\n\nCreate a `users` collection in your FaunaDB. We can then create the following `User` class:\n\n```ts\nimport { FaunaData, Model } from \"fauna-crud/dist/index\";\n\nexport default class User extends Model {\n\n    collection: string = \"users\";\n\n    @FaunaData()\n    public name: string\n\n    @FaunaData()\n    public surname: string\n}\n```\n\nThe class can now be used to set the following attributes:\n\n```ts\nconst user = new User();\nuser.name = \"Joe\"\nuser.surname = \"Blogs\"\nuser.save()\n```\n\nWhich results in the following saved into your FaunaDB\n\n```json\n{\n  \"ref\": Ref(Collection(\"users\"), \"285872613051335175\"),\n  \"ts\": 1608888218906000,\n  \"data\": {\n    \"name\": \"Joe\",\n    \"surname\": \"Blogs\"\n  }\n}\n```\n\nOther operations:\n\n```ts\n\n//Static function available on your extended model class\nconst user = User.getById(\"285872613051335175\")\n\n//Functions available on your instance\nuser.delete()\n\n//Update object after making changes to attributes\nuser.name = \"Joe2\"\nuser.update()\n\n//Check if current instance exists\nuser.exists() \n\n```\n\nYou can also check out the [tests](./tests/Model.spec.ts) for some more info\n\n\n## Limitations \u0026 ideas\n\nThis will currently only work with a flat / very basic document structure. I have not tested this with nested objects.\nIdeally the `ref, ts, key` attributes on the root model would be `readonly` and only set when something is retrieved from Fauna.\nThe current setup is more or less a workaround because I couldn't figure out how to get the constructor working properly without loosing\nthe typings on your created child model.\n\nThere is potential to play around with foreign document relations using the `ref` when loading an instance and then parse the associated document with `getById()`.\n\nWe could reverse the `getDataFields()` method in order to fetch remote document fields and then use that to auto generate models based on existing remote schemas and automatically add the `@FaunaData()` annotations with a binary that makes various options available as a cli script.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattvb91%2Ffaunacrud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattvb91%2Ffaunacrud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattvb91%2Ffaunacrud/lists"}