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

Add custom schema support #447

Closed
compressed opened this Issue Sep 17, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@compressed
Contributor

compressed commented Sep 17, 2016

As discussed on gitter, I want to use custom schemas with diesel. I am using postgresql. My use case is that the tables I want to query on aren't in the public schema. For example, I want to query schema_1.table_1 and schema_1.table_2, however currently, infer_schema! doesn't find them.

@drusellers

This comment has been minimized.

drusellers commented Oct 16, 2016

I also use schemas outside of public.

@sgrif sgrif added this to the 0.8 milestone Oct 19, 2016

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 19, 2016

Macros 1.1 took up a lot of time, but this will be in the next release.

@durango

This comment has been minimized.

Contributor

durango commented Nov 8, 2016

I'm wondering if setting the search_path would alleviate this issue:

SET search_path=public,tiger,postgis;

On that note, it would be important to specify which schemas diesel should infer (inferring tiger or postgis would be a waste)

sgrif added a commit that referenced this issue Dec 2, 2016

Allow custom schema names in the `table!` macro
This does not add support for `infer_schema!` with tables on schemas
other than public, but it does lay the ground work by changing the
macros to support it. I removed the `name` function from the `Table`
trait, as any code that was using that function would be broken on
tables with custom schemas.

Partially fixes #447

sgrif added a commit that referenced this issue Dec 5, 2016

Allow custom schema names in the `table!` macro
This does not add support for `infer_schema!` with tables on schemas
other than public, but it does lay the ground work by changing the
macros to support it. I removed the `name` function from the `Table`
trait, as any code that was using that function would be broken on
tables with custom schemas.

Partially fixes #447

@sgrif sgrif closed this in #515 Dec 5, 2016

@sgrif sgrif reopened this Dec 5, 2016

sgrif added a commit that referenced this issue Dec 6, 2016

Load custom schemas from `infer_schema!`
This changes `infer_table_from_schema!` to optionally take a custom
schema in the form `schema_name.table_name`, and generate different code
accordingly. `infer_schema!` will now load the names of all custom
schemas, and generate the code accordingly. Any schemas other than the
default will be wrapped in a module.

Unresolved Questions
--------------------

On basically every backend other than PG, the term "schema" is
interchangeable with "database". We almost certainly never want to load
the schemas for other databases by default. Instead of automatically
picking up the schema names, should we instead require that the schema
name be passed to `infer_schema!`? That would mean it looks something
like:

```rust
infer_schema!("dotenv:DATABASE_URL");
infer_schema!("dotenv:DATABASE_URL", "custom_schema");
```

Fixes #447.

sgrif added a commit that referenced this issue Dec 7, 2016

Load custom schemas from `infer_schema!`
This changes `infer_table_from_schema!` to optionally take a custom
schema in the form `schema_name.table_name`, and generate different code
accordingly. `infer_schema!` will now load the names of all custom
schemas, and generate the code accordingly. Any schemas other than the
default will be wrapped in a module.

Unresolved Questions
--------------------

On basically every backend other than PG, the term "schema" is
interchangeable with "database". We almost certainly never want to load
the schemas for other databases by default. Instead of automatically
picking up the schema names, should we instead require that the schema
name be passed to `infer_schema!`? That would mean it looks something
like:

```rust
infer_schema!("dotenv:DATABASE_URL");
infer_schema!("dotenv:DATABASE_URL", "custom_schema");
```

Fixes #447.

sgrif added a commit that referenced this issue Dec 7, 2016

Load custom schemas from `infer_schema!`
This changes `infer_table_from_schema!` to optionally take a custom
schema in the form `schema_name.table_name`, and generate different code
accordingly. `infer_schema!` will now load the names of all custom
schemas, and generate the code accordingly. Any schemas other than the
default will be wrapped in a module.

Unresolved Questions
--------------------

On basically every backend other than PG, the term "schema" is
interchangeable with "database". We almost certainly never want to load
the schemas for other databases by default. Instead of automatically
picking up the schema names, should we instead require that the schema
name be passed to `infer_schema!`? That would mean it looks something
like:

```rust
infer_schema!("dotenv:DATABASE_URL");
infer_schema!("dotenv:DATABASE_URL", "custom_schema");
```

Fixes #447.

sgrif added a commit that referenced this issue Dec 7, 2016

Load custom schemas from `infer_schema!`
This changes `infer_table_from_schema!` to optionally take a custom
schema in the form `schema_name.table_name`, and generate different code
accordingly. `infer_schema!` will now load the names of all custom
schemas, and generate the code accordingly. Any schemas other than the
default will be wrapped in a module.

Unresolved Questions
--------------------

On basically every backend other than PG, the term "schema" is
interchangeable with "database". We almost certainly never want to load
the schemas for other databases by default. Instead of automatically
picking up the schema names, should we instead require that the schema
name be passed to `infer_schema!`? That would mean it looks something
like:

```rust
infer_schema!("dotenv:DATABASE_URL");
infer_schema!("dotenv:DATABASE_URL", "custom_schema");
```

Fixes #447.

sgrif added a commit that referenced this issue Dec 7, 2016

Load custom schemas from `infer_schema!`
This changes `infer_table_from_schema!` to optionally take a custom
schema in the form `schema_name.table_name`, and generate different code
accordingly. `infer_schema!` will now load the names of all custom
schemas, and generate the code accordingly. Any schemas other than the
default will be wrapped in a module.

Fixes #447.

sgrif added a commit that referenced this issue Dec 8, 2016

Load custom schemas from `infer_schema!`
This changes `infer_table_from_schema!` to optionally take a custom
schema in the form `schema_name.table_name`, and generate different code
accordingly. `infer_schema!` will now load the names of all custom
schemas, and generate the code accordingly. Any schemas other than the
default will be wrapped in a module.

Fixes #447.

@sgrif sgrif closed this in #529 Dec 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment