Add toJSON()
method to custom JavaScript classes
This commit is contained in:
parent
8cfc286beb
commit
612cd39b05
3 changed files with 24 additions and 0 deletions
|
@ -1,9 +1,13 @@
|
|||
#[js::bind(object, public)]
|
||||
#[quickjs(bare)]
|
||||
#[allow(non_snake_case)]
|
||||
#[allow(unused_variables)]
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod duration {
|
||||
|
||||
use crate::sql::value::Value;
|
||||
use js::Rest;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[quickjs(class)]
|
||||
pub struct Duration {
|
||||
|
@ -26,5 +30,9 @@ pub mod duration {
|
|||
pub fn toString(&self) -> String {
|
||||
self.value.to_owned()
|
||||
}
|
||||
/// Convert the object to JSON
|
||||
pub fn toJSON(&self, args: Rest<Value>) -> String {
|
||||
self.value.to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#[js::bind(object, public)]
|
||||
#[quickjs(bare)]
|
||||
#[allow(non_snake_case)]
|
||||
#[allow(unused_variables)]
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod record {
|
||||
|
||||
use crate::sql::value::Value;
|
||||
use js::Rest;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[quickjs(class)]
|
||||
pub struct Record {
|
||||
|
@ -33,5 +37,9 @@ pub mod record {
|
|||
pub fn toString(&self) -> String {
|
||||
format!("{}:{}", self.tb, self.id)
|
||||
}
|
||||
/// Convert the object to JSON
|
||||
pub fn toJSON(&self, args: Rest<Value>) -> String {
|
||||
format!("{}:{}", self.tb, self.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#[js::bind(object, public)]
|
||||
#[quickjs(bare)]
|
||||
#[allow(non_snake_case)]
|
||||
#[allow(unused_variables)]
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod uuid {
|
||||
|
||||
use crate::sql::value::Value;
|
||||
use js::Rest;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[quickjs(class)]
|
||||
pub struct Uuid {
|
||||
|
@ -26,5 +30,9 @@ pub mod uuid {
|
|||
pub fn toString(&self) -> String {
|
||||
self.value.to_owned()
|
||||
}
|
||||
/// Convert the object to JSON
|
||||
pub fn toJSON(&self, args: Rest<Value>) -> String {
|
||||
self.value.to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue