Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document DDL #568

Open
mvysny opened this issue Jul 29, 2024 · 2 comments
Open

Document DDL #568

mvysny opened this issue Jul 29, 2024 · 2 comments

Comments

@mvysny
Copy link

mvysny commented Jul 29, 2024

Would be great if README.md documented how to run DDLs; it would help running an example code quickly on a H2 in-memory database. I only found database.executeUpdate() but I have no idea which SqlExpression to use for a DDL statement.

@mvysny
Copy link
Author

mvysny commented Jul 29, 2024

Workaround: use JDBC:

fun main() {
    val database = Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", user = "root", password = "***")

    database.useTransaction {
        it.connection.prepareStatement("""create table t_employee(
  id int not null primary key auto_increment,
  name varchar(128) not null,
  job varchar(128) not null,
  manager_id int null,
  hire_date date not null,
  salary bigint not null,
  department_id int not null
);""").executeUpdate()
    }

    for (row in database.from(Employees).select()) {
        println(row[Employees.name])
    }
}

@sidian123
Copy link

you also can see see this function: org.ktorm.database.Database#useConnection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants