Skip to content

Commit a2cd7a2

Browse files
committed
fix index accessor
1 parent cd95adc commit a2cd7a2

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

crates/bindings-macro/src/table.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,22 @@ struct ScheduledArg {
4848

4949
struct IndexArg {
5050
accessor: Ident,
51-
name: Option<LitStr>,
51+
//TODO: add canonical name
52+
// name: Option<LitStr>,
5253
is_unique: bool,
5354
kind: IndexType,
5455
}
5556

5657
impl IndexArg {
57-
fn new(accessor: Ident, kind: IndexType, name: Option<LitStr>) -> Self {
58+
fn new(accessor: Ident, kind: IndexType) -> Self {
5859
// We don't know if its unique yet.
5960
// We'll discover this once we have collected constraints.
6061
let is_unique = false;
6162
Self {
6263
accessor,
6364
is_unique,
6465
kind,
65-
name,
66+
// name,
6667
}
6768
}
6869
}
@@ -168,7 +169,7 @@ impl ScheduledArg {
168169
impl IndexArg {
169170
fn parse_meta(meta: ParseNestedMeta) -> syn::Result<Self> {
170171
let mut accessor = None;
171-
let mut name = None;
172+
let mut _name = None;
172173
let mut algo = None;
173174

174175
meta.parse_nested_meta(|meta| {
@@ -178,9 +179,9 @@ impl IndexArg {
178179
accessor = Some(meta.value()?.parse()?);
179180
}
180181
sym::name => {
181-
check_duplicate(&name, &meta)?;
182+
check_duplicate(&_name, &meta)?;
182183
let litstr: LitStr = meta.value()?.parse()?;
183-
name = Some(litstr);
184+
_name = Some(litstr);
184185
}
185186
sym::btree => {
186187
check_duplicate_msg(&algo, &meta, "index algorithm specified twice")?;
@@ -205,7 +206,7 @@ impl IndexArg {
205206
)
206207
})?;
207208

208-
Ok(IndexArg::new(accessor, kind, name))
209+
Ok(IndexArg::new(accessor, kind))
209210
}
210211

211212
fn parse_columns(meta: &ParseNestedMeta) -> syn::Result<Option<Vec<Ident>>> {
@@ -266,7 +267,7 @@ impl IndexArg {
266267
fn parse_index_attr(field: &Ident, attr: &syn::Attribute) -> syn::Result<Self> {
267268
let mut kind = None;
268269
let mut accessor: Option<Ident> = None;
269-
let mut name: Option<LitStr> = None;
270+
let mut _name: Option<LitStr> = None;
270271
attr.parse_nested_meta(|meta| {
271272
match_meta!(match meta {
272273
sym::btree => {
@@ -290,8 +291,8 @@ impl IndexArg {
290291
accessor = Some(meta.value()?.parse()?);
291292
}
292293
sym::name => {
293-
check_duplicate(&name, &meta)?;
294-
name = Some(meta.value()?.parse()?);
294+
check_duplicate(&_name, &meta)?;
295+
_name = Some(meta.value()?.parse()?);
295296
}
296297
});
297298
Ok(())
@@ -301,7 +302,7 @@ impl IndexArg {
301302

302303
// Default accessor = field name if not provided
303304
let accessor = accessor.unwrap_or_else(|| field.clone());
304-
Ok(IndexArg::new(accessor, kind, name))
305+
Ok(IndexArg::new(accessor, kind))
305306
}
306307

307308
fn validate<'a>(&'a self, table_name: &str, cols: &'a [Column<'a>]) -> syn::Result<ValidatedIndex<'a>> {
@@ -342,7 +343,7 @@ impl IndexArg {
342343
is_unique: self.is_unique,
343344
// This must be the canonical name (name used internally in database),
344345
// as it is used in `index_id_from_name` abi.
345-
index_name: self.name.as_ref().map(|s| s.value()).unwrap_or_else(gen_index_name),
346+
index_name: gen_index_name(),
346347
accessor_name: &self.accessor,
347348
kind,
348349
})
@@ -849,7 +850,7 @@ pub(crate) fn table_impl(mut args: TableArgs, item: &syn::DeriveInput) -> syn::R
849850
let columns = vec![accessor.clone()];
850851
args.indices.push(IndexArg {
851852
accessor,
852-
name: None,
853+
//name: None,
853854
is_unique: true,
854855
kind: IndexType::BTree { columns },
855856
})

0 commit comments

Comments
 (0)