{"id":15056877,"url":"https://github.com/cqerl/cqex","last_synced_at":"2025-04-09T08:09:32.864Z","repository":{"id":40372585,"uuid":"48305391","full_name":"cqerl/cqex","owner":"cqerl","description":"Idiomatic Cassandra client for Elixir","archived":false,"fork":false,"pushed_at":"2022-05-12T06:33:01.000Z","size":67,"stargazers_count":76,"open_issues_count":3,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T05:10:01.732Z","etag":null,"topics":["cassandra","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/cqerl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-20T03:06:35.000Z","updated_at":"2024-05-24T15:34:58.000Z","dependencies_parsed_at":"2022-07-15T21:30:50.298Z","dependency_job_id":null,"html_url":"https://github.com/cqerl/cqex","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqerl%2Fcqex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqerl%2Fcqex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqerl%2Fcqex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cqerl%2Fcqex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cqerl","download_url":"https://codeload.github.com/cqerl/cqex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247999861,"owners_count":21031046,"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":["cassandra","elixir"],"created_at":"2024-09-24T21:57:28.615Z","updated_at":"2025-04-09T08:09:32.839Z","avatar_url":"https://github.com/cqerl.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cqex\nModern Cassandra driver for Elixir, using [cqerl][1] underneath.\n\n### Installation\n\nAdd `cqex` to your application's mix.exs:\n\n```elixir\ndefp deps do\n  [\n    # ...\n    {:cqex, \"~\u003e 1.0.0\"},\n    # ...\n  ]\nend\n```\n\nAnd update your applications list in the project:\n\n```elixir\ndef application do\n  [applications: [:cqex]]\nend\n```\n\n### Usage examples\n\nIf you're using a single cluster, in your project's config/config.exs:\n\n****\n\n```elixir\nuse Mix.Config\n\nconfig :cqerl, \n  cassandra_nodes: [{\"10.0.0.1\", 9042}, {\"10.0.0.2\", 9042}],\n  keyspace: \"keyspace\"\n```\n\nThen, create a transient client connection\n\n```elixir\nclient = CQEx.Client.new!\n```\n\nFetch the complete list of users, and creating a list out of it using `Enum`\n\n```elixir\nall_users = client |\u003e CQEx.Query.call!(\"SELECT * FROM users;\") |\u003e Enum.to_list\n# =\u003e [ list of users... ]\n\nall_users[0]\n# =\u003e %{ ... first_user ... }\n```\n\nChain queries and using `Stream` and `Enum` to get the result set in small pages.\n\n```elixir\n\nalias CQEx.Query, as: Q\n\nbase = %Q{\n  statement: \"INSERT INTO animals (name, legs, friendly) values (?, ?, ?);\",\n  values: %{ legs: 4, friendly: true }\n}\n\n^base = Q.new \n|\u003e Q.statement(\"INSERT INTO animals (name, legs, friendly) values (?, ?, ?);\")\n|\u003e Q.put(:legs, 4)\n|\u003e Q.put(:friendly, true)\n\nanimals_by_pair = client\n|\u003e Q.call!(\"CREATE TABLE IF NOT EXISTS animals (name text PRIMARY KEY, legs tinyint, friendly boolean);\")\n|\u003e Q.call!( base |\u003e Q.merge(%{ name: \"cat\", friendly: false }) )\n|\u003e Q.call!( base |\u003e Q.put(:name, \"dog\") )\n|\u003e Q.call!( base |\u003e Q.merge(%{ name: \"bonobo\", legs: 2 }) )\n|\u003e Q.call!(\"SELECT * FROM animals;\")\n|\u003e Stream.chunk(2)\n\nanimals_by_pair\n|\u003e Enum.at(0)\n\n# =\u003e [ %{name: \"cat\", legs: 4, friendly: false}, %{name: \"dog\", legs: 4, friendly: true} ]\n\nanimals_by_pair\n|\u003e Enum.to_list\n\n# =\u003e [ \n#      [ %{name: \"cat\", legs: 4, friendly: false}, %{name: \"dog\", legs: 4, friendly: true} ], \n#      [ %{name: \"bonobo\", legs: 2, friendly: true} ] \n#    ]\n\n```\n\nUse comprehensions on the results of a CQL query\n\n```elixir\nfor %{ legs: leg_count, name: name, friendly: true } \u003c- Q.call!(client, \"SELECT * FROM animals\"), \n  leg_count == 4,\n  do: \"#{name} has four legs\"\n  \n# =\u003e [ \"dog has four legs\" ]\n```\n\nIf you want different clusters, in your project's `config/config.exs`:\n\n```elixir\nuse Mix.Config\n\nconfig :cqerl, \n  cassandra_clusters: [\n    cluster1: { [{\"10.0.0.1\", 9042}, {\"10.0.0.2\", 9042}], [keyspace: \"keyspace1\"] },\n    cluster2: { [{\"10.0.0.1\", 9042}, {\"10.0.0.2\", 9042}], [keyspace: \"keyspace2\"] }\n  ]\n```\n\nThen, in your code\n\n```elixir\nclient = CQEx.Client.new! :cluster1\n# etc\n```\n\n[1]: https://github.com/matehat/cqerl/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqerl%2Fcqex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcqerl%2Fcqex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcqerl%2Fcqex/lists"}