{"id":16250925,"url":"https://github.com/hasumikin/aurora-data-api","last_synced_at":"2025-04-08T12:27:16.220Z","repository":{"id":57697887,"uuid":"496570205","full_name":"hasumikin/aurora-data-api","owner":"hasumikin","description":"A kind of ORM for Amazon Aurora Serverless NOT depending on ActiveRecord","archived":false,"fork":false,"pushed_at":"2022-06-03T06:55:01.000Z","size":239,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T08:33:30.871Z","etag":null,"topics":["aurora","poro","postgresql","ruby","serverless"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hasumikin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-26T10:09:33.000Z","updated_at":"2024-08-27T15:28:42.000Z","dependencies_parsed_at":"2022-09-26T21:01:57.767Z","dependency_job_id":null,"html_url":"https://github.com/hasumikin/aurora-data-api","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasumikin%2Faurora-data-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasumikin%2Faurora-data-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasumikin%2Faurora-data-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hasumikin%2Faurora-data-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hasumikin","download_url":"https://codeload.github.com/hasumikin/aurora-data-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247840962,"owners_count":21005017,"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":["aurora","poro","postgresql","ruby","serverless"],"created_at":"2024-10-10T15:07:46.709Z","updated_at":"2025-04-08T12:27:16.186Z","avatar_url":"https://github.com/hasumikin.png","language":"Ruby","readme":"# AuroraDataApi [![Ruby](https://github.com/hasumikin/aurora-data-api/actions/workflows/main.yml/badge.svg)](https://github.com/hasumikin/aurora-data-api/actions/workflows/main.yml)\n\nA kind of ORM for Amazon Aurora Serverless v1.\n\nSupposing that you are using Ruby (typically on AWS Lambda) as an application, Aurora Serverless v1 (NOT v2) as a database, and Data API as a database adapter.\n\nThis gem doesn't depend on ActiveRecord and takes advantage of PORO (plain old Ruby object) like Array, Hash, and Struct internally so you can easily hack.\n\nPostgreSQL is the only target as of now.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'aurora-data-api'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install aurora-data-api\n\n## Usage\n\nLet's say we're developing a blog that has three models:\n\n- User: able to post an entry and to comment on any entry\n- Entry: an article\n- Comment: a comment on an entry\n\n```ruby\nclass User \u003c AuroraDataApi::Model\n  schema do\n    col :name,             String\n    col :internet_account, String\n    timestamp # Creates :created_at and :updated_at\n  end\n\n  def twitter\n    \"https://twitter.com/#{internet_account}\"\n  end\nend\n\nclass Entry \u003c AuroraDataApi::Model\n  schema do\n    col :user,  :User  # User.to_sym\n    col :title, String\n    col :body,  String\n    timestamp\n  end\nend\n\nclass Comment \u003c AuroraDataApi::Model\n  schema do\n    col :user,  :User  # User.to_sym\n    col :entry, :Entry, table: :entries  #...(*)\n    col :body,  String\n    timestamp\n  end\nend\n\n# (*)\n# The plural of \"entry\" is too difficult for aurora-data-api.\n# So you need to explicitly tell gem the table name.\n```\n\n\n```ruby\nrequire_relative '../models/user'\nUserDepot = AuroraDataApi::Depot[User] do\nend\n\nrequire_relative '../models/entry'\nEntryDepot = AuroraDataApi::Depot[Entry] do\nend\n\nrequire_relative '../models/comment'\nCommentDepot = AuroraDataApi::Depot[Comment] do\nend\n```\n\n### Insert a user\n\n```ruby\nuser = User.new(name: \"HASUMI Hitoshi\", internet_account: \"hasumikin\")\nuser.id                 # =\u003e nil\nUserDepot.insert(user)  # =\u003e 1\nuser.id                 # =\u003e 1\n```\n\n### Update the user\n\n```ruby\nuser.internet_account = \"HASUMIKIN\"\nUserDepot.update(user)  # =\u003e true (false if failed)\nuser.internet_account   # =\u003e \"HASUMIKIN\"\n```\n\n### Delete the user\n\n```ruby\nUserDepot.delete(user)  # =\u003e true (false if failed)\nuser.id                 # =\u003e nil\n```\n\n### Find a user\n\n```ruby\nhasumikin = UserDepot.select(\n  \"WHERE internet_account = :internet_account\",\n  internet_account: \"hasumikin\"\n).first\n```\n\n### Post an entry\n\n```ruby\nmy_entry = Entry.new(\n  user: hasumikin,\n  title: \"My first article\",\n  body: \"Hey, this is an article about Ruby.\"\n)\nEntryDepot.insert(my_entry)\n```\n\n### Update the entry\n\n```ruby\nmy_entry.body = \"Hey, this is an article about Ruby whick is a happy language!\"\nEntryDepot.update(my_entry)\n```\n\n### Delete the entry\n\n```ruby\nEntryDepot.delete(my_entry)\n```\n\n### Count comments\n\n```ruby\ncount = CommentDepot.count(\n  \"WHERE entry_id = :entry_id\",\n  entry_id: my_entry.id\n)\n```\n\n### Select comments\n\n```ruby\ncomments = CommentDepot.select(\u003c\u003c~SQL, user_id: hasumikin.id)\n  INNER JOIN ENTRY ON entry.id = comment.entry_id\n  WHERE entry.user_id = :user_id\n  ORDER BY comment.created_at\n  LIMIT 10 OFFSET 0\nSQL\ncomments.class                 # =\u003e Array\ncomments.first.class           # =\u003e Comment\ncomments.first.body            # =\u003e \"I have a question, ...\"\ncomments.first.entry.class     # =\u003e Entry\ncomments.first.entry.title     # =\u003e \"My first article\"\ncomments.first.entry.user.name # =\u003e \"HASUMI Hitoshi\"\n```\n\nAs of the current version, the last call `comments.first.entry.user.name` will execute another query so it may cause an N+1 problem.\n\n## Typical application structure\n\n```sh\nyour_app\n├── Gemfile        # It includes `gem 'aurora-data-api'`\n├── app\n│   ├── handlers  # You may have Lambda functions here\n│   ├── models\n│   │   ├── comment.rb\n│   │   ├── entry.rb\n│   │   └── user.rb\n│   └── depots\n│       ├── comment_depot.rb\n│       ├── entry_depot.rb\n│       └── user_depot.rb\n├── db\n│   └── shcema.sql\n└── serverless.yml # aurora-data-api is perfect for Serverless Framework\n```\n\naurora-data-api doesn't have a generator to initiate the structure.\nMake it manually instead like:\n\n```sh\nmkdir -p app/models app/depots db\n```\n\n## Migration\n\nThe following command overwrites `db/schema.sql` (for only PostgreSQL) by aggregating `app/models/*.rb`\n\n```sh\nbundle exec aurora-data-api export\n```\n\nWe recommend to use @k0kubun's sqldef to manage migration.\n\nSee [k0kubun/sqldef](https://github.com/k0kubun/sqldef)\n\n## Environment variables\n\nThe following variables should be defined:\n\n```ruby\nENV['PGDATABASE']       # Database name\nENV['RDS_RESOURCE_ARN'] # Resource ARN of RDS Aurora Serverless\nENV['RDS_SECRET_ARN']   # Secret ARN that is stored in AWS Secrets Manager\nENV['TZ']               # (Optional) Timezone. Internal default is \"UTC\"\n```\n\nRDS_SECRET_ARN has to be attached to an IAM role of the \"application\".\n\n## Example project with Serverless Project\n\nSee [example](https://github.com/hasumikin/aurora-data-api/tree/master/example)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/hasumikin/aurora-data-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hasumikin/aurora-data-api/blob/master/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the AuroraDataApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hasumikin/aurora-data-api/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasumikin%2Faurora-data-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhasumikin%2Faurora-data-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhasumikin%2Faurora-data-api/lists"}