Simple and powerful key-value store (with examples)
This article provides code examples for different use cases of the skate
command. skate
is a simple and powerful key-value store that allows you to store and retrieve data easily. Whether you want to store information in a default or specific database, skate
has you covered. Let’s explore some common use cases and see how skate
can be used effectively.
Storing a key and a value on the default database
To store a key and a value on the default database, you can use the following command:
skate set "key" "value"
Motivation: This use case is ideal when you want to quickly store a key-value pair without specifying a specific database. It is useful for temporary or test data that doesn’t require extensive organization.
Explanation: The skate set
command is used to set a key-value pair in the default database. The first argument "key"
specifies the key you want to store, and the second argument "value"
specifies the corresponding value.
Example Output: If you run skate list
after executing the above command, you will see the key "key"
listed with its corresponding value.
Showing keys saved on the default database
To show your keys saved on the default database, you can use the following command:
skate list
Motivation: This use case is useful when you want to retrieve and view all the keys saved on the default database. It allows you to quickly see the available data.
Explanation: The skate list
command is used to list all the keys saved on the default database. It doesn’t require any additional arguments.
Example Output: If you have previously stored keys on the default database, running skate list
will display a list of those keys.
Deleting a key and value from the default database
To delete a key and its corresponding value from the default database, you can use the following command:
skate delete "key"
Motivation: Deleting a key and its value can be necessary when you no longer need certain data or want to update it. It allows you to maintain a clean and relevant dataset.
Explanation: The skate delete
command is used to delete a key-value pair from the default database. The argument "key"
specifies the key you want to delete.
Example Output: After executing the above command, if you run skate list
, the key specified will no longer be listed.
Creating a new key and value in a new database
To create a new key and value in a new database, you can use the following command:
skate set "key"@"database_name" "value"
Motivation: Creating a new key-value pair in a specific database allows you to organize your data based on different contexts or categories. It helps maintain clarity and separation between different datasets.
Explanation: The skate set
command is used to set a key-value pair in a specific database. The first argument "key"
specifies the key you want to store, followed by "@"
to indicate the database, and finally "database_name"
specifies the name of the new database. The last argument "value"
specifies the value for the key.
Example Output: After executing the above command, if you run skate list @"database_name"
, you will see the key "key"
listed with its corresponding value in the specified database.
Showing keys saved in a non-default database
To show your keys saved in a specific database, you can use the following command:
skate list @"database_name"
Motivation: When you have multiple databases, it can be helpful to view and manage the keys in a specific database. This use case allows you to focus on the data stored in a particular context.
Explanation: The skate list
command with the argument "@"
followed by "database_name"
is used to list all the keys saved in a specific database.
Example Output: Executing the above command will display a list of keys stored in the specified database.
Deleting a key and value from a specific database
To delete a key and its corresponding value from a specific database, you can use the following command:
skate delete "key"@"database_name"
Motivation: Deleting a key and its value from a specific database is useful when you want to remove specific data from a particular context. It allows you to maintain the integrity of each database.
Explanation: The skate delete
command with the argument "@"
followed by "database_name"
is used to delete a key-value pair from a specific database. The argument "key"
specifies the key you want to delete.
Example Output: After executing the above command, if you run skate list @"database_name"
, the key specified will no longer be listed in the specified database.
Showing the databases available
To show the databases available, you can use the following command:
skate list-dbs
Motivation: This use case provides an overview of all the databases available, allowing you to see how your data is organized. It helps you manage and navigate between different datasets effectively.
Explanation: The skate list-dbs
command is used to list all the databases available.
Example Output: Running the above command will display a list of databases that have been created.
Deleting a local database and pulling down a fresh copy from Charm Cloud
To delete a local database and pull down a fresh copy from Charm Cloud, you can use the following command:
skate reset @"database_name"
Motivation: Sometimes, it is necessary to reset or start fresh with a specific database. This use case allows you to delete the local copy of the database and retrieve a fresh copy from the Charm Cloud.
Explanation: The skate reset
command with the argument "@"
followed by "database_name"
is used to delete the local copy of a specific database and pull down a fresh copy from the Charm Cloud.
Example Output: After executing the above command, the local copy of the specified database will be deleted, and a fresh copy will be retrieved from the Charm Cloud.
In summary, skate
is a versatile command-line tool for managing key-value stores. With these examples, you can store, retrieve, and delete key-value pairs in different databases, providing flexibility and organization to your data management.