Astra.Schema.Rest (astra v0.5.0)

Functions for working with the REST (aka keyspace) schema APIs

Link to this section Summary

Functions

create a new keyspace (NOTE: Not avialable on Astra)

create a new table

delete a keyspace (NOTE: Not avialable on Astra)

retrieve a list of all keyspaces in the cluster

get a specific table in a keyspace

get tables for a keyspace

Link to this section Functions

Link to this function

create_keyspace(name)

create a new keyspace (NOTE: Not avialable on Astra)

Link to this function

create_table(keyspace, table)

create a new table

See https://stargate.io/docs/stargate/1.0/developers-guide/api_ref/openapi_rest_ref.html#Table for the table creation schema

Examples

> table = %{
              columnDefinitions: [
                %{name: "id", typeDefinition: "text"},
                %{name: "name", typeDefinition: "text"},
                %{name: "description", typeDefinition: "text"}
              ],
              name: "demo",
              primaryKey: %{clusteringKey: ["name"], partitionKey: ["id"]}
            }
          
> Astra.Schema.Rest.create_table("test", table)
Link to this function

delete_keyspace(name)

delete a keyspace (NOTE: Not avialable on Astra)

Link to this function

drop_table(keyspace, table)

drop a table

Examples

> Astra.Schema.Rest.drop_table("test", "table_name")
Link to this function

get_keyspaces()

retrieve a list of all keyspaces in the cluster

Link to this function

get_table(keyspace, table)

get a specific table in a keyspace

Examples

iex> Astra.Schema.Rest.get_table("system_auth", "role_members") {:ok, %{

columnDefinitions: [
  %{name: "role", static: false, typeDefinition: "varchar"},
  %{name: "member", static: false, typeDefinition: "varchar"}
],
keyspace: "system_auth",
name: "role_members",
primaryKey: %{clusteringKey: ["member"], partitionKey: ["role"]},
tableOptions: %{
  clusteringExpression: [%{column: "member", order: "ASC"}],
  defaultTimeToLive: 0
}

} }

Link to this function

get_tables(keyspace)

get tables for a keyspace

Examples

Astra.Schema.Rest.get_tables("system_auth") {:ok, [

%{
  columnDefinitions: [
    %{name: "role", static: false, typeDefinition: "varchar"},
    %{name: "member", static: false, typeDefinition: "varchar"}
  ],
  keyspace: "system_auth",
  name: "role_members",
  primaryKey: %{
    clusteringKey: ["member"],
    partitionKey: ["role"]
  },
  tableOptions: %{
    clusteringExpression: [%{column: "member", order: "ASC"}],
    defaultTimeToLive: 0
  }
},
%{
  columnDefinitions: [
    %{name: "role", static: false, typeDefinition: "varchar"},
    %{name: "resource", static: false, typeDefinition: "varchar"},
    %{
      name: "grantables",
      static: false,
      typeDefinition: "set<varchar>"
    },
    %{
      name: "permissions",
      static: false,
      typeDefinition: "set<varchar>"
    },
    %{
      name: "restricted",
      static: false,
      typeDefinition: "set<varchar>"
    }
  ],
  keyspace: "system_auth",
  name: "role_permissions",
  primaryKey: %{
    clusteringKey: ["resource"],
    partitionKey: ["role"]
  },
  tableOptions: %{
    clusteringExpression: [%{column: "resource", order: "ASC"}],
    defaultTimeToLive: 0
  }
},
%{
  columnDefinitions: [
    %{name: "role", static: false, typeDefinition: "varchar"},
    %{
      name: "can_login",
      static: false,
      typeDefinition: "boolean"
    },
    %{
      name: "is_superuser",
      static: false,
      typeDefinition: "boolean"
    },
    %{
      name: "member_of",
      static: false,
      typeDefinition: "set<varchar>"
    },
    %{
      name: "salted_hash",
      static: false,
      typeDefinition: "varchar"
    }
  ],
  keyspace: "system_auth",
  name: "roles",
  primaryKey: %{clusteringKey: [], partitionKey: ["role"]},
  tableOptions: %{clusteringExpression: [], defaultTimeToLive: 0}
}

]}