diff --git a/examples/.gitignore b/examples/.gitignore index 823664ae1f..158f9b50d2 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -7,3 +7,4 @@ optimistic_transaction_example options_file_example simple_example transaction_example +speedb_is_awesome_example \ No newline at end of file diff --git a/examples/Makefile b/examples/Makefile index 55e7e285cf..a535e7b589 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -19,7 +19,7 @@ CFLAGS += -Wstrict-prototypes .PHONY: clean static_lib -all: simple_example column_families_example compact_files_example c_simple_example optimistic_transaction_example transaction_example compaction_filter_example options_file_example rocksdb_backup_restore_example +all: simple_example column_families_example compaction_filter_example compact_files_example c_simple_example optimistic_transaction_example transaction_example options_file_example rocksdb_backup_restore_example speedb_is_awesome_example simple_example: static_lib simple_example.cc $(CXX) $(CXXFLAGS) $@.cc -o$@ ../$(LIBNAME).a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) @@ -51,11 +51,14 @@ options_file_example: static_lib options_file_example.cc multi_processes_example: static_lib multi_processes_example.cc $(CXX) $(CXXFLAGS) $@.cc -o$@ ../$(LIBNAME).a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) -rocksdb_backup_restore_example: librocksdb rocksdb_backup_restore_example.cc - $(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) +speedb_is_awesome_example: static_lib speedb_is_awesome_example.cc + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../$(LIBNAME).a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) + +rocksdb_backup_restore_example: static_lib rocksdb_backup_restore_example.cc + $(CXX) $(CXXFLAGS) $@.cc -o$@ ../$(LIBNAME).a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS) clean: - rm -rf ./simple_example ./column_families_example ./compact_files_example ./compaction_filter_example ./c_simple_example c_simple_example.o ./optimistic_transaction_example ./transaction_example ./options_file_example ./multi_processes_example ./rocksdb_backup_restore_example + rm -rf ./simple_example ./column_families_example ./compact_files_example ./compaction_filter_example ./c_simple_example c_simple_example.o ./optimistic_transaction_example ./transaction_example ./options_file_example ./multi_processes_example ./rocksdb_backup_restore_example ./speedb_is_awesome_example static_lib: LIBNAME="$(LIBNAME)" $(MAKE) -C .. static_lib diff --git a/examples/speedb_is_awesome_example.cc b/examples/speedb_is_awesome_example.cc new file mode 100644 index 0000000000..7ae5226d91 --- /dev/null +++ b/examples/speedb_is_awesome_example.cc @@ -0,0 +1,44 @@ +#include + +#include "rocksdb/db.h" +#include "rocksdb/options.h" + +using ROCKSDB_NAMESPACE::DB; +using ROCKSDB_NAMESPACE::Options; +using ROCKSDB_NAMESPACE::ReadOptions; +using ROCKSDB_NAMESPACE::Status; +using ROCKSDB_NAMESPACE::WriteOptions; + +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\speedb_is_awesome_example"; +#else +std::string kDBPath = "/tmp/speedb_is_awesome_example"; +#endif + +int main() { + // Open the storage + DB* db = nullptr; + Options options; + // create the DB if it's not already present + options.create_if_missing = true; + Status s = DB::Open(options, kDBPath, &db); + assert(s.ok()); + + // append new entry + std::string key = "key_1"; + std::string put_value = "Speedb is awesome!"; + s = db->Put(WriteOptions(), key, put_value); + assert(s.ok()); + + // retrieve entry + std::string get_value; + s = db->Get(ReadOptions(), key, &get_value); + assert(s.ok()); + assert(get_value == put_value); + std::cout << get_value << std::endl; + + // close DB + s = db->Close(); + assert(s.ok()); + return 0; +} \ No newline at end of file