Add new functions for gnerating v4 and v7 UUIDs

Related to #1353
This commit is contained in:
Tobie Morgan Hitchcock 2022-10-16 23:22:34 +01:00
parent 810e174c63
commit c9243dec3c
8 changed files with 48 additions and 4 deletions

View file

@ -1,8 +1,18 @@
[build]
rustflags = ["--cfg", "uuid_unstable"]
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[target.x86_64-unknown-linux-musl]
rustflags = [
"--cfg", "uuid_unstable",
"-C", "target-feature=+crt-static"
]
[target.x86_64-pc-windows-msvc]
rustflags = [
"--cfg", "uuid_unstable",
"-C", "target-feature=+crt-static",
"-C", "link-arg=/NODEFAULTLIB:libvcruntimed.lib",
"-C", "link-arg=/NODEFAULTLIB:vcruntime.lib",

14
Cargo.lock generated
View file

@ -279,6 +279,15 @@ dependencies = [
"syn",
]
[[package]]
name = "atomic"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c"
dependencies = [
"autocfg",
]
[[package]]
name = "atomic-polyfill"
version = "0.1.10"
@ -4271,10 +4280,11 @@ checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372"
[[package]]
name = "uuid"
version = "1.1.2"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83"
dependencies = [
"atomic",
"getrandom 0.2.7",
"serde",
]

View file

@ -74,7 +74,7 @@ thiserror = "1.0.37"
tikv = { version = "0.1.0", package = "tikv-client", optional = true }
trice = "0.1.0"
url = "2.3.1"
uuid = { version = "1.1.2", features = ["serde", "v4"] }
uuid = { version = "1.2.1", features = ["serde", "v4", "v7"] }
bcrypt = "0.13.0"
[dev-dependencies]

View file

@ -149,6 +149,8 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec<Value>) -> Result<Va
"rand::int" => rand::int,
"rand::string" => rand::string,
"rand::time" => rand::time,
"rand::uuid::v4" => rand::uuid::v4,
"rand::uuid::v7" => rand::uuid::v7,
"rand::uuid" => rand::uuid,
"rand" => rand::rand,
//

View file

@ -123,3 +123,18 @@ pub fn time((range,): (Option<(i64, i64)>,)) -> Result<Value, Error> {
pub fn uuid(_: ()) -> Result<Value, Error> {
Ok(Uuid::new().into())
}
pub mod uuid {
use crate::err::Error;
use crate::sql::uuid::Uuid;
use crate::sql::value::Value;
pub fn v4(_: ()) -> Result<Value, Error> {
Ok(Uuid::new_v4().into())
}
pub fn v7(_: ()) -> Result<Value, Error> {
Ok(Uuid::new_v7().into())
}
}

View file

@ -396,6 +396,8 @@ fn function_rand(i: &str) -> IResult<&str, &str> {
tag("rand::int"),
tag("rand::string"),
tag("rand::time"),
tag("rand::uuid::v4"),
tag("rand::uuid::v7"),
tag("rand::uuid"),
tag("rand"),
))(i)

View file

@ -39,6 +39,12 @@ impl Uuid {
pub fn new() -> Self {
Self(uuid::Uuid::new_v4())
}
pub fn new_v4() -> Self {
Self(uuid::Uuid::new_v4())
}
pub fn new_v7() -> Self {
Self(uuid::Uuid::now_v7())
}
pub fn to_raw(&self) -> String {
self.0.to_string()
}

View file

@ -6,7 +6,6 @@
buildSpec = with pkgs; {
nativeBuildInputs = with pkgsStatic; [ stdenv.cc openssl ];
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
CARGO_BUILD_TARGET = target;
OPENSSL_NO_VENDOR = "true";