import { getTableName } from "drizzle-orm";
import { escapeName } from "../dialect.js";
// ---------------------------------------------------------------------------
// Builder
// ---------------------------------------------------------------------------
export class SybaseDeleteBuilder {
    table;
    dialect;
    session;
    whereCondition;
    constructor(table, dialect, session) {
        this.table = table;
        this.dialect = dialect;
        this.session = session;
    }
    where(condition) {
        this.whereCondition = this.dialect.sqlToQuery(condition);
        return this;
    }
    toSQL() {
        return this.buildSql();
    }
    async execute() {
        const rawSql = this.buildSql();
        const result = await this.session.execute(rawSql);
        return { rowCount: result.rowCount, affectedRows: result.affectedRows };
    }
    then(onfulfilled, onrejected) {
        return this.execute().then(onfulfilled, onrejected);
    }
    // ---------------------------------------------------------------------------
    // Private
    // ---------------------------------------------------------------------------
    buildSql() {
        const tableName = escapeName(getTableName(this.table));
        let query = `delete from ${tableName}`;
        if (this.whereCondition) {
            query += ` where ${this.whereCondition}`;
        }
        return query;
    }
}
//# sourceMappingURL=delete.js.map