mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-07 01:04:26 +01:00
remove Id
This commit is contained in:
@@ -24,7 +24,7 @@ pub fn translate_alter_table(
|
||||
) -> Result<ProgramBuilder> {
|
||||
let (table_name, alter_table) = alter;
|
||||
let table_name = table_name.name.as_str();
|
||||
if schema.table_has_indexes(&table_name) && !schema.indexes_enabled() {
|
||||
if schema.table_has_indexes(table_name) && !schema.indexes_enabled() {
|
||||
// Let's disable altering a table with indices altogether instead of checking column by
|
||||
// column to be extra safe.
|
||||
crate::bail_parse_error!(
|
||||
@@ -32,10 +32,7 @@ pub fn translate_alter_table(
|
||||
);
|
||||
}
|
||||
|
||||
let Some(original_btree) = schema
|
||||
.get_table(&table_name)
|
||||
.and_then(|table| table.btree())
|
||||
else {
|
||||
let Some(original_btree) = schema.get_table(table_name).and_then(|table| table.btree()) else {
|
||||
return Err(LimboError::ParseError(format!(
|
||||
"no such table: {table_name}"
|
||||
)));
|
||||
@@ -56,7 +53,7 @@ pub fn translate_alter_table(
|
||||
)));
|
||||
}
|
||||
|
||||
let (dropped_index, column) = btree.get_column(&column_name).ok_or_else(|| {
|
||||
let (dropped_index, column) = btree.get_column(column_name).ok_or_else(|| {
|
||||
LimboError::ParseError(format!("no such column: \"{column_name}\""))
|
||||
})?;
|
||||
|
||||
@@ -70,7 +67,7 @@ pub fn translate_alter_table(
|
||||
|| btree.unique_sets.as_ref().is_some_and(|set| {
|
||||
set.iter().any(|set| {
|
||||
set.iter()
|
||||
.any(|(name, _)| name == &normalize_ident(&column_name))
|
||||
.any(|(name, _)| name == &normalize_ident(column_name))
|
||||
})
|
||||
})
|
||||
{
|
||||
@@ -218,13 +215,13 @@ pub fn translate_alter_table(
|
||||
let rename_from = old.as_str();
|
||||
let rename_to = new.as_str();
|
||||
|
||||
if btree.get_column(&rename_from).is_none() {
|
||||
if btree.get_column(rename_from).is_none() {
|
||||
return Err(LimboError::ParseError(format!(
|
||||
"no such column: \"{rename_from}\""
|
||||
)));
|
||||
};
|
||||
|
||||
if btree.get_column(&rename_to).is_some() {
|
||||
if btree.get_column(rename_to).is_some() {
|
||||
return Err(LimboError::ParseError(format!(
|
||||
"duplicate column name: \"{rename_from}\""
|
||||
)));
|
||||
@@ -311,7 +308,7 @@ pub fn translate_alter_table(
|
||||
ast::AlterTableBody::RenameTo(new_name) => {
|
||||
let new_name = new_name.as_str();
|
||||
|
||||
if schema.get_table(&new_name).is_some() {
|
||||
if schema.get_table(new_name).is_some() {
|
||||
return Err(LimboError::ParseError(format!(
|
||||
"there is already another table or index with this name: {new_name}"
|
||||
)));
|
||||
|
||||
@@ -560,7 +560,7 @@ impl ToTokens for UpdatePlan {
|
||||
.unwrap();
|
||||
|
||||
ast::Set {
|
||||
col_names: ast::DistinctNames::single(ast::Name::from_str(&col_name)),
|
||||
col_names: ast::DistinctNames::single(ast::Name::from_str(col_name)),
|
||||
expr: set_expr.clone(),
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -279,7 +279,7 @@ pub fn translate_insert(
|
||||
// allocate cursor id's for each btree index cursor we'll need to populate the indexes
|
||||
// (idx name, root_page, idx cursor id)
|
||||
let idx_cursors = schema
|
||||
.get_indices(&table_name.as_str())
|
||||
.get_indices(table_name.as_str())
|
||||
.iter()
|
||||
.map(|idx| {
|
||||
(
|
||||
@@ -445,7 +445,7 @@ pub fn translate_insert(
|
||||
});
|
||||
|
||||
let index = schema
|
||||
.get_index(&table_name.as_str(), &index_col_mapping.idx_name)
|
||||
.get_index(table_name.as_str(), &index_col_mapping.idx_name)
|
||||
.expect("index should be present");
|
||||
|
||||
let record_reg = program.alloc_register();
|
||||
|
||||
@@ -158,7 +158,7 @@ pub fn translate_inner(
|
||||
ast::Stmt::DropIndex {
|
||||
if_exists,
|
||||
idx_name,
|
||||
} => translate_drop_index(&idx_name.name.as_str(), if_exists, schema, program)?,
|
||||
} => translate_drop_index(idx_name.name.as_str(), if_exists, schema, program)?,
|
||||
ast::Stmt::DropTable {
|
||||
if_exists,
|
||||
tbl_name,
|
||||
|
||||
@@ -234,7 +234,7 @@ fn update_pragma(
|
||||
if let Some(table) = &opts.table() {
|
||||
// make sure that we have table created
|
||||
program = translate_create_table(
|
||||
QualifiedName::single(ast::Name::from_str(&table)),
|
||||
QualifiedName::single(ast::Name::from_str(table)),
|
||||
false,
|
||||
ast::CreateTableBody::columns_and_constraints_from_definition(
|
||||
turso_cdc_table_columns(),
|
||||
|
||||
@@ -290,7 +290,7 @@ fn check_automatic_pk_index_required(
|
||||
bail_parse_error!("No such column: {}", name.as_str());
|
||||
}
|
||||
Ok(PrimaryKeyColumnInfo {
|
||||
name: &name.as_str(),
|
||||
name: name.as_str(),
|
||||
is_descending: matches!(
|
||||
col.order,
|
||||
Some(ast::SortOrder::Desc)
|
||||
|
||||
@@ -1100,7 +1100,7 @@ pub fn parse_pragma_bool(expr: &Expr) -> Result<bool> {
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::*;
|
||||
use turso_sqlite3_parser::ast::{self, Expr, Id, Literal, Name, Operator::*, Type};
|
||||
use turso_sqlite3_parser::ast::{self, Expr, Literal, Name, Operator::*, Type};
|
||||
|
||||
#[test]
|
||||
fn test_normalize_ident() {
|
||||
|
||||
@@ -1117,20 +1117,6 @@ pub struct GroupBy {
|
||||
pub having: Option<Box<Expr>>, // HAVING clause on a non-aggregate query
|
||||
}
|
||||
|
||||
/// identifier or one of several keywords or `INDEXED`
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Id(pub String);
|
||||
|
||||
impl Id {
|
||||
/// Constructor
|
||||
pub fn from_token(ty: YYCODETYPE, token: Token) -> Self {
|
||||
Self(from_token(ty, token))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO ids (identifier or string)
|
||||
|
||||
/// identifier or string or `CROSS` or `FULL` or `INNER` or `LEFT` or `NATURAL` or `OUTER` or `RIGHT`.
|
||||
#[derive(Clone, Debug, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
@@ -1180,6 +1166,7 @@ impl Name {
|
||||
}
|
||||
|
||||
/// Identifying from a string
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
let bytes = s.as_bytes();
|
||||
if s.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user