mirror of
https://github.com/getml/sqlgen.git
synced 2026-05-04 22:21:58 -05:00
Added documentation for the timestamps
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sqlgen.hpp>
|
||||
#include <sqlgen/postgres.hpp>
|
||||
|
||||
namespace test_timestamp_dry {
|
||||
|
||||
struct TestTable {
|
||||
std::string field1;
|
||||
int32_t field2;
|
||||
sqlgen::PrimaryKey<uint32_t> id;
|
||||
sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S"> ts;
|
||||
};
|
||||
|
||||
TEST(postgres, test_timestamp_dry) {
|
||||
const auto query = sqlgen::CreateTable<TestTable>{};
|
||||
|
||||
const auto expected =
|
||||
R"(CREATE TABLE IF NOT EXISTS "TestTable" ("field1" TEXT NOT NULL, "field2" INTEGER NOT NULL, "id" INTEGER NOT NULL, "ts" TIMESTAMP NOT NULL, PRIMARY KEY ("id"));)";
|
||||
|
||||
EXPECT_EQ(sqlgen::postgres::to_sql(query), expected);
|
||||
}
|
||||
} // namespace test_timestamp_dry
|
||||
@@ -0,0 +1,23 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sqlgen.hpp>
|
||||
#include <sqlgen/postgres.hpp>
|
||||
|
||||
namespace test_timestamp_with_tz_dry {
|
||||
|
||||
struct TestTable {
|
||||
std::string field1;
|
||||
int32_t field2;
|
||||
sqlgen::PrimaryKey<uint32_t> id;
|
||||
sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S%z"> ts;
|
||||
};
|
||||
|
||||
TEST(postgres, test_timestamp_with_tz_dry) {
|
||||
const auto query = sqlgen::CreateTable<TestTable>{};
|
||||
|
||||
const auto expected =
|
||||
R"(CREATE TABLE IF NOT EXISTS "TestTable" ("field1" TEXT NOT NULL, "field2" INTEGER NOT NULL, "id" INTEGER NOT NULL, "ts" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));)";
|
||||
|
||||
EXPECT_EQ(sqlgen::postgres::to_sql(query), expected);
|
||||
}
|
||||
} // namespace test_timestamp_with_tz_dry
|
||||
Reference in New Issue
Block a user