Implement layer validation

next
Sayan Nandan 2 years ago
parent 8d789bd166
commit b8dd8135f1
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -26,6 +26,8 @@
#[cfg(test)]
use core::mem;
use crate::engine::mem::WordRW;
use {
crate::engine::{
self,
@ -48,10 +50,10 @@ pub struct Datacell {
impl Datacell {
// bool
pub fn new_bool(b: bool) -> Self {
unsafe { Self::new(TagClass::Bool, DataRaw::word(SystemDword::store_qw(b as _))) }
unsafe { Self::new(TagClass::Bool, DataRaw::word(SystemDword::store(b))) }
}
pub unsafe fn read_bool(&self) -> bool {
self.data.word.load_qw() == 1
self.load_word()
}
pub fn try_bool(&self) -> Option<bool> {
self.checked_tag(TagClass::Bool, || unsafe { self.read_bool() })
@ -61,15 +63,10 @@ impl Datacell {
}
// uint
pub fn new_uint(u: u64) -> Self {
unsafe {
Self::new(
TagClass::UnsignedInt,
DataRaw::word(SystemDword::store_qw(u)),
)
}
unsafe { Self::new(TagClass::UnsignedInt, DataRaw::word(SystemDword::store(u))) }
}
pub unsafe fn read_uint(&self) -> u64 {
self.data.word.load_qw()
self.load_word()
}
pub fn try_uint(&self) -> Option<u64> {
self.checked_tag(TagClass::UnsignedInt, || unsafe { self.read_uint() })
@ -79,15 +76,10 @@ impl Datacell {
}
// sint
pub fn new_sint(u: i64) -> Self {
unsafe {
Self::new(
TagClass::SignedInt,
DataRaw::word(SystemDword::store_qw(u as _)),
)
}
unsafe { Self::new(TagClass::SignedInt, DataRaw::word(SystemDword::store(u))) }
}
pub unsafe fn read_sint(&self) -> i64 {
self.data.word.load_qw() as _
self.load_word()
}
pub fn try_sint(&self) -> Option<i64> {
self.checked_tag(TagClass::SignedInt, || unsafe { self.read_sint() })
@ -97,15 +89,10 @@ impl Datacell {
}
// float
pub fn new_float(f: f64) -> Self {
unsafe {
Self::new(
TagClass::Float,
DataRaw::word(SystemDword::store_qw(f.to_bits())),
)
}
unsafe { Self::new(TagClass::Float, DataRaw::word(SystemDword::store(f))) }
}
pub unsafe fn read_float(&self) -> f64 {
f64::from_bits(self.data.word.load_qw())
self.load_word()
}
pub fn try_float(&self) -> Option<f64> {
self.checked_tag(TagClass::Float, || unsafe { self.read_float() })
@ -119,13 +106,13 @@ impl Datacell {
unsafe {
Self::new(
TagClass::Bin,
DataRaw::word(SystemDword::store_fat(md.as_ptr() as usize, md.len())),
DataRaw::word(SystemDword::store((md.as_ptr(), md.len()))),
)
}
}
pub unsafe fn read_bin(&self) -> &[u8] {
let [p, l] = self.data.word.load_fat();
slice::from_raw_parts(p as *mut u8, l)
let (p, l) = self.load_word();
slice::from_raw_parts::<u8>(p, l)
}
pub fn try_bin(&self) -> Option<&[u8]> {
self.checked_tag(TagClass::Bin, || unsafe { self.read_bin() })
@ -139,13 +126,13 @@ impl Datacell {
unsafe {
Self::new(
TagClass::Str,
DataRaw::word(SystemDword::store_fat(md.as_ptr() as usize, md.len())),
DataRaw::word(SystemDword::store((md.as_ptr(), md.len()))),
)
}
}
pub unsafe fn read_str(&self) -> &str {
let [p, l] = self.data.word.load_fat();
str::from_utf8_unchecked(slice::from_raw_parts(p as *mut u8, l))
let (p, l) = self.load_word();
str::from_utf8_unchecked(slice::from_raw_parts(p, l))
}
pub fn try_str(&self) -> Option<&str> {
self.checked_tag(TagClass::Str, || unsafe { self.read_str() })
@ -241,6 +228,9 @@ impl Datacell {
pub fn kind(&self) -> TagClass {
self.tag
}
unsafe fn load_word<'a, T: WordRW<NativeQword, Target<'a> = T>>(&'a self) -> T {
self.data.word.ld()
}
}
impl fmt::Debug for Datacell {
@ -314,8 +304,8 @@ impl Drop for Datacell {
fn drop(&mut self) {
match self.tag {
TagClass::Str | TagClass::Bin => unsafe {
let [p, l] = self.data.word.load_fat();
engine::mem::dealloc_array(p as *mut u8, l)
let (p, l) = self.load_word();
engine::mem::dealloc_array::<u8>(p, l)
},
TagClass::List => unsafe { ManuallyDrop::drop(&mut self.data.rwl) },
_ => {}

@ -26,6 +26,12 @@
pub mod cell;
use crate::engine::{
data::tag::{DataTag, FullTag, TagSelector},
error::{DatabaseError, DatabaseResult},
ql::ddl::syn::LayerSpec,
};
// FIXME(@ohsayan): update this!
#[derive(Debug)]
@ -37,3 +43,140 @@ impl PartialEq for ModelView {
true
}
}
/*
Layer
*/
static G: [u8; 15] = [0, 13, 12, 5, 6, 4, 3, 6, 1, 10, 4, 5, 7, 5, 5];
static S1: [u8; 7] = [13, 9, 4, 14, 2, 4, 7];
static S2: [u8; 7] = [12, 8, 2, 6, 4, 9, 9];
static LUT: [(&str, FullTag); 14] = [
("bool", FullTag::BOOL),
("uint8", FullTag::new_uint(TagSelector::UInt8)),
("uint16", FullTag::new_uint(TagSelector::UInt16)),
("uint32", FullTag::new_uint(TagSelector::UInt32)),
("uint64", FullTag::new_uint(TagSelector::UInt64)),
("sint8", FullTag::new_sint(TagSelector::SInt8)),
("sint16", FullTag::new_sint(TagSelector::SInt16)),
("sint32", FullTag::new_sint(TagSelector::SInt32)),
("sint64", FullTag::new_sint(TagSelector::SInt64)),
("float32", FullTag::new_float(TagSelector::Float32)),
("float64", FullTag::new_float(TagSelector::Float64)),
("binary", FullTag::BIN),
("string", FullTag::STR),
("list", FullTag::LIST),
];
#[derive(Debug, PartialEq, Clone)]
pub struct LayerView(Box<[Layer]>);
impl LayerView {
pub fn layers(&self) -> &[Layer] {
&self.0
}
pub fn parse_layers(spec: Vec<LayerSpec>) -> DatabaseResult<Self> {
let mut layers = spec.into_iter().rev();
let mut okay = true;
let mut fin = false;
let mut layerview = Vec::with_capacity(layers.len());
while (layers.len() != 0) & okay & !fin {
let LayerSpec { ty, props } = layers.next().unwrap();
okay &= props.is_empty(); // FIXME(@ohsayan): you know what to do here
match Layer::get_layer(&ty) {
Some(l) => {
fin = l.tag.tag_selector() != TagSelector::List;
layerview.push(l);
}
None => okay = false,
}
}
okay &= fin & (layers.len() == 0);
if okay {
Ok(Self(layerview.into_boxed_slice()))
} else {
Err(DatabaseError::DdlModelInvalidTypeDefinition)
}
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct Layer {
tag: FullTag,
config: [usize; 2],
}
impl Layer {
pub const fn bool() -> Self {
Self::empty(FullTag::BOOL)
}
pub const fn uint8() -> Self {
Self::empty(FullTag::new_uint(TagSelector::UInt8))
}
pub const fn uint16() -> Self {
Self::empty(FullTag::new_uint(TagSelector::UInt16))
}
pub const fn uint32() -> Self {
Self::empty(FullTag::new_uint(TagSelector::UInt32))
}
pub const fn uint64() -> Self {
Self::empty(FullTag::new_uint(TagSelector::UInt64))
}
pub const fn sint8() -> Self {
Self::empty(FullTag::new_sint(TagSelector::SInt8))
}
pub const fn sint16() -> Self {
Self::empty(FullTag::new_sint(TagSelector::SInt16))
}
pub const fn sint32() -> Self {
Self::empty(FullTag::new_sint(TagSelector::SInt32))
}
pub const fn sint64() -> Self {
Self::empty(FullTag::new_sint(TagSelector::SInt64))
}
pub const fn float32() -> Self {
Self::empty(FullTag::new_float(TagSelector::Float32))
}
pub const fn float64() -> Self {
Self::empty(FullTag::new_float(TagSelector::Float64))
}
pub const fn bin() -> Self {
Self::empty(FullTag::BIN)
}
pub const fn str() -> Self {
Self::empty(FullTag::STR)
}
pub const fn list() -> Self {
Self::empty(FullTag::LIST)
}
}
impl Layer {
const fn new(tag: FullTag, config: [usize; 2]) -> Self {
Self { tag, config }
}
const fn empty(tag: FullTag) -> Self {
Self::new(tag, [0; 2])
}
fn hf(key: &[u8], v: [u8; 7]) -> u16 {
let mut tot = 0;
let mut i = 0;
while i < key.len() {
tot += v[i % v.len()] as u16 * key[i] as u16;
i += 1;
}
tot % 15
}
fn pf(key: &[u8]) -> u16 {
(G[Self::hf(key, S1) as usize] as u16 + G[Self::hf(key, S2) as usize] as u16) % 15
}
fn get_layer(ident: &str) -> Option<Self> {
let idx = Self::pf(ident.as_bytes()) as usize;
if idx < LUT.len() && LUT[idx].0 == ident {
Some(Self::empty(LUT[idx].1))
} else {
None
}
}
}

@ -27,3 +27,5 @@
// ddl
// space
mod space;
// model
mod model;

@ -0,0 +1,69 @@
/*
* Created on Thu Mar 02 2023
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
mod layer_validation {
use crate::engine::{
core::model::{Layer, LayerView},
error::DatabaseError,
ql::{ast::parse_ast_node_multiple_full, tests::lex_insecure as lex},
};
#[test]
fn string() {
let tok = lex(b"string").unwrap();
let spec = parse_ast_node_multiple_full(&tok).unwrap();
let view = LayerView::parse_layers(spec).unwrap();
assert_eq!(view.layers(), [Layer::str()]);
}
#[test]
fn nested_list() {
let tok = lex(b"list { type: list { type: string } }").unwrap();
let spec = parse_ast_node_multiple_full(&tok).unwrap();
let view = LayerView::parse_layers(spec).unwrap();
assert_eq!(view.layers(), [Layer::list(), Layer::list(), Layer::str()]);
}
#[test]
fn invalid_list() {
let tok = lex(b"list").unwrap();
let spec = parse_ast_node_multiple_full(&tok).unwrap();
assert_eq!(
LayerView::parse_layers(spec).unwrap_err(),
DatabaseError::DdlModelInvalidTypeDefinition
);
}
#[test]
fn invalid_flat() {
let tok = lex(b"string { type: string }").unwrap();
let spec = parse_ast_node_multiple_full(&tok).unwrap();
assert_eq!(
LayerView::parse_layers(spec).unwrap_err(),
DatabaseError::DdlModelInvalidTypeDefinition
);
}
}

@ -117,7 +117,7 @@ pub unsafe trait Dataspec1D: DataspecMeta1D + DataspecRaw1D {
// bool
/// Load a bool (this is unsafe for logical verity)
unsafe fn read_bool_uck(&self) -> bool {
self.data().load::<bool>()
self.data().ld()
}
/// Load a bool
fn read_bool_try(&self) -> Option<bool> {
@ -135,7 +135,7 @@ pub unsafe trait Dataspec1D: DataspecMeta1D + DataspecRaw1D {
// uint
/// Load a uint (this is unsafe for logical verity)
unsafe fn read_uint_uck(&self) -> u64 {
self.data().load::<u64>()
self.data().ld()
}
/// Load a uint
fn read_uint_try(&self) -> Option<u64> {
@ -153,7 +153,7 @@ pub unsafe trait Dataspec1D: DataspecMeta1D + DataspecRaw1D {
// sint
/// Load a sint (unsafe for logical verity)
unsafe fn read_sint_uck(&self) -> i64 {
self.data().load::<i64>()
self.data().ld()
}
/// Load a sint
fn read_sint_try(&self) -> Option<i64> {
@ -169,7 +169,7 @@ pub unsafe trait Dataspec1D: DataspecMeta1D + DataspecRaw1D {
// float
/// Load a float (unsafe for logical verity)
unsafe fn read_float_uck(&self) -> f64 {
self.data().load::<f64>()
self.data().ld()
}
/// Load a float
fn read_float_try(&self) -> Option<f64> {
@ -187,7 +187,7 @@ pub unsafe trait Dataspec1D: DataspecMeta1D + DataspecRaw1D {
/// ## Safety
/// Are you a binary? Did you store it correctly? Are you a victim of segfaults?
unsafe fn read_bin_uck(&self) -> &[u8] {
let (p, l) = self.data().load::<(*const u8, usize)>();
let (p, l) = self.data().ld();
slice::from_raw_parts(p, l)
}
/// Load a bin

@ -99,6 +99,15 @@ impl FullTag {
unique,
}
}
pub const fn new_uint(selector: TagSelector) -> Self {
Self::new(TagClass::UnsignedInt, selector, TagUnique::UnsignedInt)
}
pub const fn new_sint(selector: TagSelector) -> Self {
Self::new(TagClass::SignedInt, selector, TagUnique::SignedInt)
}
pub const fn new_float(selector: TagSelector) -> Self {
Self::new(TagClass::Float, selector, TagUnique::Illegal)
}
}
macro_rules! fulltag {

@ -88,4 +88,6 @@ pub enum DatabaseError {
DdlSpaceAlreadyExists,
/// the space doesn't exist
DdlSpaceNotFound,
/// bad definition for some typedef in a model
DdlModelInvalidTypeDefinition,
}

@ -36,12 +36,18 @@ pub trait SystemQword: SystemTword {
{
WordRW::store(v)
}
fn load<'a, T>(&'a self) -> T::Target<'a>
fn ld_special<'a, T>(&'a self) -> T::Target<'a>
where
T: WordRW<Self>,
{
<T>::load(self)
}
fn ld<'a, T>(&'a self) -> T
where
T: WordRW<Self, Target<'a> = T>,
{
<T>::load(self)
}
}
/// Native tripe pointer stack (must also be usable as a double pointer stack, see [`SystemDword`])
@ -54,12 +60,18 @@ pub trait SystemTword: SystemDword {
{
WordRW::store(v)
}
fn load<'a, T>(&'a self) -> T::Target<'a>
fn ld_special<'a, T>(&'a self) -> T::Target<'a>
where
T: WordRW<Self>,
{
<T>::load(self)
}
fn ld<'a, T>(&'a self) -> T
where
T: WordRW<Self, Target<'a> = T>,
{
<T>::load(self)
}
}
/// Native double pointer stack
@ -74,12 +86,18 @@ pub trait SystemDword: Sized {
{
WordRW::store(v)
}
fn load<'a, T>(&'a self) -> T::Target<'a>
fn ld_special<'a, T>(&'a self) -> T::Target<'a>
where
T: WordRW<Self>,
{
<T>::load(self)
}
fn ld<'a, T>(&'a self) -> T
where
T: WordRW<Self, Target<'a> = T>,
{
<T>::load(self)
}
}
impl SystemDword for NativeDword {

@ -217,12 +217,12 @@ pub(super) fn rfold_tymeta<'a, Qd: QueryData<'a>>(
#[derive(Debug, PartialEq)]
/// A layer contains a type and corresponding metadata
pub struct Layer<'a> {
ty: Ident<'a>,
props: DictGeneric,
pub struct LayerSpec<'a> {
pub(in crate::engine) ty: Ident<'a>,
pub(in crate::engine) props: DictGeneric,
}
impl<'a> Layer<'a> {
impl<'a> LayerSpec<'a> {
//// Create a new layer
pub const fn new(ty: Ident<'a>, props: DictGeneric) -> Self {
Self { ty, props }
@ -243,7 +243,7 @@ states! {
fn rfold_layers<'a, Qd: QueryData<'a>>(
mut mstate: LayerFoldState,
state: &mut State<'a, Qd>,
layers: &mut Vec<Layer<'a>>,
layers: &mut Vec<LayerSpec<'a>>,
) {
let mut ty = MaybeInit::uninit();
let mut props = Default::default();
@ -296,7 +296,7 @@ fn rfold_layers<'a, Qd: QueryData<'a>>(
}
if ((mstate == LayerFoldState::FINAL) | (mstate == LayerFoldState::FINAL_OR_OB)) & state.okay()
{
layers.push(Layer {
layers.push(LayerSpec {
ty: unsafe { ty.take() },
props,
});
@ -311,7 +311,7 @@ pub struct Field<'a> {
/// the field name
field_name: Ident<'a>,
/// layers
layers: Vec<Layer<'a>>,
layers: Vec<LayerSpec<'a>>,
/// is null
null: bool,
/// is primary
@ -319,7 +319,12 @@ pub struct Field<'a> {
}
impl<'a> Field<'a> {
pub fn new(field_name: Ident<'a>, layers: Vec<Layer<'a>>, null: bool, primary: bool) -> Self {
pub fn new(
field_name: Ident<'a>,
layers: Vec<LayerSpec<'a>>,
null: bool,
primary: bool,
) -> Self {
Self {
field_name,
layers,
@ -364,12 +369,12 @@ impl<'a> Field<'a> {
/// An [`ExpandedField`] is a full field definition with advanced metadata
pub struct ExpandedField<'a> {
field_name: Ident<'a>,
layers: Vec<Layer<'a>>,
layers: Vec<LayerSpec<'a>>,
props: DictGeneric,
}
impl<'a> ExpandedField<'a> {
pub fn new(field_name: Ident<'a>, layers: Vec<Layer<'a>>, props: DictGeneric) -> Self {
pub fn new(field_name: Ident<'a>, layers: Vec<LayerSpec<'a>>, props: DictGeneric) -> Self {
Self {
field_name,
layers,
@ -481,7 +486,7 @@ mod impls {
use {
super::{
rfold_dict, rfold_layers, rfold_tymeta, DictFoldState, DictGeneric, ExpandedField,
Field, Layer, LayerFoldState,
Field, LayerFoldState, LayerSpec,
},
crate::engine::{
error::LangResult,
@ -498,7 +503,7 @@ mod impls {
Self::parse_multiple(state).map(Vec::from)
}
}
impl<'a> ASTNode<'a> for Layer<'a> {
impl<'a> ASTNode<'a> for LayerSpec<'a> {
// important: upstream must verify this
const VERIFY: bool = true;
fn _from_state<Qd: QueryData<'a>>(state: &mut State<'a, Qd>) -> LangResult<Self> {

@ -190,23 +190,23 @@ mod tymeta {
}
mod layer {
use super::*;
use crate::engine::ql::{ast::parse_ast_node_multiple_full, ddl::syn::Layer};
use crate::engine::ql::{ast::parse_ast_node_multiple_full, ddl::syn::LayerSpec};
#[test]
fn layer_mini() {
let tok = lex_insecure(b"string").unwrap();
let layers = parse_ast_node_multiple_full::<Layer>(&tok).unwrap();
let layers = parse_ast_node_multiple_full::<LayerSpec>(&tok).unwrap();
assert_eq!(
layers,
vec![Layer::new(Ident::from("string"), null_dict! {})]
vec![LayerSpec::new(Ident::from("string"), null_dict! {})]
);
}
#[test]
fn layer() {
let tok = lex_insecure(b"string { maxlen: 100 }").unwrap();
let layers = parse_ast_node_multiple_full::<Layer>(&tok).unwrap();
let layers = parse_ast_node_multiple_full::<LayerSpec>(&tok).unwrap();
assert_eq!(
layers,
vec![Layer::new(
vec![LayerSpec::new(
Ident::from("string"),
null_dict! {
"maxlen" => Lit::UnsignedInt(100)
@ -217,24 +217,24 @@ mod layer {
#[test]
fn layer_plus() {
let tok = lex_insecure(b"list { type: string }").unwrap();
let layers = parse_ast_node_multiple_full::<Layer>(&tok).unwrap();
let layers = parse_ast_node_multiple_full::<LayerSpec>(&tok).unwrap();
assert_eq!(
layers,
vec![
Layer::new(Ident::from("string"), null_dict! {}),
Layer::new(Ident::from("list"), null_dict! {})
LayerSpec::new(Ident::from("string"), null_dict! {}),
LayerSpec::new(Ident::from("list"), null_dict! {})
]
);
}
#[test]
fn layer_pro() {
let tok = lex_insecure(b"list { unique: true, type: string, maxlen: 10 }").unwrap();
let layers = parse_ast_node_multiple_full::<Layer>(&tok).unwrap();
let layers = parse_ast_node_multiple_full::<LayerSpec>(&tok).unwrap();
assert_eq!(
layers,
vec![
Layer::new(Ident::from("string"), null_dict! {}),
Layer::new(
LayerSpec::new(Ident::from("string"), null_dict! {}),
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true),
@ -250,18 +250,18 @@ mod layer {
b"list { unique: true, type: string { ascii_only: true, maxlen: 255 }, maxlen: 10 }",
)
.unwrap();
let layers = parse_ast_node_multiple_full::<Layer>(&tok).unwrap();
let layers = parse_ast_node_multiple_full::<LayerSpec>(&tok).unwrap();
assert_eq!(
layers,
vec![
Layer::new(
LayerSpec::new(
Ident::from("string"),
null_dict! {
"ascii_only" => Lit::Bool(true),
"maxlen" => Lit::UnsignedInt(255)
}
),
Layer::new(
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true),
@ -285,17 +285,17 @@ mod layer {
}
";
let expected = vec![
Layer::new(Ident::from("string"), null_dict!()),
Layer::new(
LayerSpec::new(Ident::from("string"), null_dict!()),
LayerSpec::new(
Ident::from("list"),
null_dict! {
"maxlen" => Lit::UnsignedInt(100),
},
),
Layer::new(Ident::from("list"), null_dict!("unique" => Lit::Bool(true))),
LayerSpec::new(Ident::from("list"), null_dict!("unique" => Lit::Bool(true))),
];
fuzz_tokens(tok.as_slice(), |should_pass, new_tok| {
let layers = parse_ast_node_multiple_full::<Layer>(&new_tok);
let layers = parse_ast_node_multiple_full::<LayerSpec>(&new_tok);
let ok = layers.is_ok();
if should_pass {
assert_eq!(layers.unwrap(), expected);
@ -309,7 +309,7 @@ mod fields {
super::*,
crate::engine::ql::{
ast::parse_ast_node_full,
ddl::syn::{Field, Layer},
ddl::syn::{Field, LayerSpec},
lex::Ident,
},
};
@ -321,7 +321,7 @@ mod fields {
f,
Field::new(
Ident::from("username"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
false,
false
)
@ -335,7 +335,7 @@ mod fields {
f,
Field::new(
Ident::from("username"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
false,
true
)
@ -357,7 +357,7 @@ mod fields {
f,
Field::new(
Ident::from("username"),
[Layer::new(
[LayerSpec::new(
Ident::from("string"),
null_dict! {
"maxlen" => Lit::UnsignedInt(10),
@ -390,14 +390,14 @@ mod fields {
Field::new(
Ident::from("notes"),
[
Layer::new(
LayerSpec::new(
Ident::from("string"),
null_dict! {
"maxlen" => Lit::UnsignedInt(255),
"ascii_only" => Lit::Bool(true),
}
),
Layer::new(
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true)
@ -417,7 +417,7 @@ mod schemas {
ast::parse_ast_node_full,
ddl::{
crt::CreateModel,
syn::{Field, Layer},
syn::{Field, LayerSpec},
},
};
#[test]
@ -443,13 +443,13 @@ mod schemas {
vec![
Field::new(
Ident::from("username"),
vec![Layer::new(Ident::from("string"), null_dict! {})],
vec![LayerSpec::new(Ident::from("string"), null_dict! {})],
false,
true,
),
Field::new(
Ident::from("password"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
false,
false,
)
@ -482,19 +482,19 @@ mod schemas {
vec![
Field::new(
Ident::from("username"),
vec![Layer::new(Ident::from("string"), null_dict! {})],
vec![LayerSpec::new(Ident::from("string"), null_dict! {})],
false,
true,
),
Field::new(
Ident::from("password"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
false,
false,
),
Field::new(
Ident::from("profile_pic"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
true,
false,
)
@ -532,27 +532,27 @@ mod schemas {
vec![
Field::new(
Ident::from("username"),
vec![Layer::new(Ident::from("string"), null_dict! {})],
vec![LayerSpec::new(Ident::from("string"), null_dict! {})],
false,
true
),
Field::new(
Ident::from("password"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
false,
false
),
Field::new(
Ident::from("profile_pic"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
true,
false
),
Field::new(
Ident::from("notes"),
vec![
Layer::new(Ident::from("string"), null_dict! {}),
Layer::new(
LayerSpec::new(Ident::from("string"), null_dict! {}),
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true)
@ -601,27 +601,27 @@ mod schemas {
vec![
Field::new(
Ident::from("username"),
vec![Layer::new(Ident::from("string"), null_dict! {})],
vec![LayerSpec::new(Ident::from("string"), null_dict! {})],
false,
true
),
Field::new(
Ident::from("password"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
false,
false
),
Field::new(
Ident::from("profile_pic"),
vec![Layer::new(Ident::from("binary"), null_dict! {})],
vec![LayerSpec::new(Ident::from("binary"), null_dict! {})],
true,
false
),
Field::new(
Ident::from("notes"),
vec![
Layer::new(Ident::from("string"), null_dict! {}),
Layer::new(
LayerSpec::new(Ident::from("string"), null_dict! {}),
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true)
@ -646,7 +646,7 @@ mod dict_field_syntax {
use super::*;
use crate::engine::ql::{
ast::parse_ast_node_full,
ddl::syn::{ExpandedField, Layer},
ddl::syn::{ExpandedField, LayerSpec},
};
#[test]
fn field_syn_mini() {
@ -656,7 +656,7 @@ mod dict_field_syntax {
ef,
ExpandedField::new(
Ident::from("username"),
vec![Layer::new(Ident::from("string"), null_dict! {})],
vec![LayerSpec::new(Ident::from("string"), null_dict! {})],
null_dict! {}
)
)
@ -677,7 +677,7 @@ mod dict_field_syntax {
ef,
ExpandedField::new(
Ident::from("username"),
vec![Layer::new(Ident::from("string"), null_dict! {})],
vec![LayerSpec::new(Ident::from("string"), null_dict! {})],
null_dict! {
"nullable" => Lit::Bool(false),
},
@ -704,7 +704,7 @@ mod dict_field_syntax {
ef,
ExpandedField::new(
Ident::from("username"),
vec![Layer::new(
vec![LayerSpec::new(
Ident::from("string"),
null_dict! {
"minlen" => Lit::UnsignedInt(6),
@ -741,13 +741,13 @@ mod dict_field_syntax {
ExpandedField::new(
Ident::from("notes"),
vec![
Layer::new(
LayerSpec::new(
Ident::from("string"),
null_dict! {
"ascii_only" => Lit::Bool(true),
}
),
Layer::new(
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true),
@ -819,7 +819,7 @@ mod alter_model_add {
ast::parse_ast_node_full,
ddl::{
alt::{AlterKind, AlterModel},
syn::{ExpandedField, Layer},
syn::{ExpandedField, LayerSpec},
},
};
#[test]
@ -837,7 +837,7 @@ mod alter_model_add {
AlterKind::Add(
[ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {},
)]
.into()
@ -861,7 +861,7 @@ mod alter_model_add {
AlterKind::Add(
[ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {
"nullable" => Lit::Bool(true)
},
@ -887,7 +887,7 @@ mod alter_model_add {
AlterKind::Add(
[ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {
"nullable" => Lit::Bool(true)
},
@ -928,7 +928,7 @@ mod alter_model_add {
[
ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {
"nullable" => Lit::Bool(true)
},
@ -936,13 +936,13 @@ mod alter_model_add {
ExpandedField::new(
Ident::from("another"),
[
Layer::new(
LayerSpec::new(
Ident::from("string"),
null_dict! {
"maxlen" => Lit::UnsignedInt(255)
}
),
Layer::new(
LayerSpec::new(
Ident::from("list"),
null_dict! {
"unique" => Lit::Bool(true)
@ -967,7 +967,7 @@ mod alter_model_update {
ast::parse_ast_node_full,
ddl::{
alt::{AlterKind, AlterModel},
syn::{ExpandedField, Layer},
syn::{ExpandedField, LayerSpec},
},
};
@ -987,7 +987,7 @@ mod alter_model_update {
AlterKind::Update(
[ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {},
)]
.into()
@ -1011,7 +1011,7 @@ mod alter_model_update {
AlterKind::Update(
[ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {},
)]
.into()
@ -1040,7 +1040,7 @@ mod alter_model_update {
AlterKind::Update(
[ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {
"nullable" => Lit::Bool(true)
},
@ -1075,14 +1075,14 @@ mod alter_model_update {
[
ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {
"nullable" => Lit::Bool(true)
},
),
ExpandedField::new(
Ident::from("myfield2"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {},
)
]
@ -1118,14 +1118,14 @@ mod alter_model_update {
[
ExpandedField::new(
Ident::from("myfield"),
[Layer::new(Ident::from("string"), null_dict! {})].into(),
[LayerSpec::new(Ident::from("string"), null_dict! {})].into(),
null_dict! {
"nullable" => Lit::Bool(true)
},
),
ExpandedField::new(
Ident::from("myfield2"),
[Layer::new(
[LayerSpec::new(
Ident::from("string"),
null_dict! {"maxlen" => Lit::UnsignedInt(255)}
)]

Loading…
Cancel
Save