Last active
March 3, 2020 22:23
-
-
Save fogti/911ad922cec6c9b95269102523efdbf8 to your computer and use it in GitHub Desktop.
SQL repr in zsdatab API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <zsdatable.hpp> | |
#include <iostream> | |
int main() { | |
zsdatab::metadata mt(':'); | |
mt += { "k", "w", "v" }; | |
zsdatab::table tab(mt); | |
// insert something into table | |
///... | |
///... | |
const auto sp_k = ???; // ? = k | |
const auto sp_w = ???; // ? < w | |
const auto fi_w = mt.get_field_nr("w"); | |
const auto fi_v = mt.get_field_nr("v"); | |
zsdatab::table result(zsdatab::metadata(mt.separator()) += { "w", "v" }); | |
// break after 1 iteration | |
for(auto &&i : tab.filter("k", sp_k).sort().data()) { | |
if(i[fi_w] > sp_w) | |
result += { i[fi_w], i[fi_v] }; | |
break; | |
} | |
if(!result.empty()) | |
cout << result.get_metadata().serialize(result.data().front()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE t(k, w, v); | |
CREATE INDEX i ON t(k ASC, w ASC); | |
-- insert something into the table | |
SELECT w, v FROM t WHERE ? = k AND ? < w ORDER BY w LIMIT 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment