Skip to content

Releases: Brendonovich/prisma-client-rust

0.6.1

09 Sep 16:49
Compare
Choose a tag to compare

Got a small release here with some improvements to create_many and a change to how types are exported when using rspc.

create_many only accepts scalar fields

When implementing create_many I made the mistake of using the same argument structure of create and put it in a Vec.
This is not correct as create_many does not permit using relation fields with connect, instead it only allows setting scalar fields of the model. Models' create utility and create_many have been changed to reflect this fix.
This is a breaking change, but any create_many involving a relation would always result in an error, so I don't feel a new minor version is warranted.

create_many has skip_duplicates function

Prisma Client JS has a skipDuplicates option, which was not implemented in 0.6.0. Now it is possible to call skip_duplicates after create_many, providing the same functionality as the JS option.

Model types in rspc bindings do not include relations

Previously, model types exported via rspc exactly mirrored model Data structs, containing all scalar fields as well as optional relation fields.
After integrating this and replacing uses of with/fetch with include in Spacedrive, I have decided to encourage utilising the extra type safety provided by include and removed all relation fields from model types, so that they only contain a model's scalar fields.
More information can be found in the docs.

0.6.0

15 Nov 13:30
Compare
Choose a tag to compare

Perhaps the biggest update yet to Prisma Client Rust is here - version 0.6.0! Plenty of new features, new integrations, official Prisma sponsorship thanks to the Prisma FOSS Fund, new docs, a Discord server, and enough functionality to make Prisma Client Rust (in my opinion) better than Diesel, SeaORM and SQLx - especially for web development!
Now, lets check out 0.6.0's breaking changes:

Breaking Changes

Migration Guide

Field name specifiers are no longer needed for required fields in create

Previously, it was necessary to wrap required arguments in create calls in a call to set or link to identify which field was being targeted, but this was redundant - each argument already corresponds to a specific field.
For this reason it is no longer necessary to include set or link calls for required fields.
This change pairs well with having inlay hints enabled in your editor, as VSCode/neovim/whatever you're using can remind you which argument corresponds to which field, rather than having to type it in code.
Here's some stripped down examples of what this change looks like:

  • create(user::name::set("Brendan".to_string()), vec![]) -> create("Brendan".to_string(), vec![])
  • create(user::profile::link(profile::id::equals(0)), vec![]) -> create(profile::id::equals(0), vec![])

update_* and delete_* are now dedicated actions

update_* and delete_* being created from find queries was a behaviour inherited from Prisma Client Go, and now they are dedicated actions.

  • find_unique(where).update(data) -> update(where, data)
  • find_many(where).update(data) -> update_many(where, data)
  • find_unique(where).delete() -> delete(where)
  • find_many(where).delete() -> delete_many(where)

link and unlink renamed

link and unlink have been renamed to connect and disconnect in an effort to keep consistency with Prisma Client JS.

Cursor types removed

It turns out that the specifier needed for the cursor field function can just be a UniqueWhereParam, so field::equals() can be used as a drop-in replacement to field::cursor().

JSON values are parsed correctly

Previously, all JSON values fetched from a database would be converted to a serde_json::Value::String, rather than their correct serde_json::Value representation.

Renamed + more usable QueryError

prisma_client_rust::queries::Error has been renamed to QueryError, and is now accessible as prisma_client_rust::QueryError.

The error_is_type function has been removed in favour of QueryError::is_prisma_error(&self), which can be called with a generic UserFacingError in the same way as error_is_type.

update and delete no longer return an Option

While Prisma Client JS returns Data | null for find_first/unique, it does not do so for update and delete, so Prisma Client Rust will do the same.
In my opinion this makes more sense, as finding data comes with a decent expectation that a record may not exist. For mutations though, you're attempting to target a specific record and failing to do so should be an error.

Relation accessors error type is now RelationNotFetchedError

As requested in #118, relation accessor errors are no longer just strings, but have a dedicated error type that is compatible with anyhow and thiserror.

Feature resolver version 2 now required

The version of quaint (a Prisma crate) being used now has platform-specific features for some of its dependencies. This requires using version 2 of Cargo's feature resolver. In non-workspace projects, this can be done by setting edition = "2021" in the Cargo.toml. In workspace projects, this can be done by setting resolver = "2" in the root Cargo.toml. More info is available in the installation documentation.


If I've missed any breaking changes please let me know, I'm still getting used to this open source maintainer thing!
Now, on to the fun new stuff:

New Features

select and include

The feature I'm most excited about is the new select and include macros & query builder functions.
Fully type-safe relation fetching & the ability to select exactly the fields you would like to fetch from a model.
You can read all about it in the docs, but here's a small example:

// Type inside Vec is anonymous and does not exist outside of the call to `include`
let posts: Vec<_> = client
    .post()
    .find_many(vec![])
    .include(post::include!({ // Every model gets select & include macros
        comments: select { // Nested select/include is supported
            id // Only select the exact fields you need!
        }
    }))
    .exec()
    .await?;

// Macro output type is equivalent to 
struct Data {
    id: String,
    title: String,
    comments: comments::Data
}

mod comments {
    pub struct Data {
        id: String
    }
}

While with/fetch works well and has excellent autocomplete support, determining whether a relation has been fetched is left to runtime checks, rather than being enforced by data types. If you're fine with doing runtime checks then with/fetch will serve you well, but if you need to select specific fields then you'll have to use the select! macro.

Going forward, I will try to bring as many relation-fetching features to both with/fetch and select/include, but some may simply require the magic of macros.

count query

Retrieving the number of records that match some filters is now super easy. Check the docs for an example!

create_many query

For all databases except SQLite, create_many is now available and can be read about here.
For those of you using SQLite, create_many support can be enabled by adding the sqlite-create-many feature to both prisma-client-rust and prisma-client-rust-cli. Please keep in mind that this feature is EXPERIMENTAL and is not supported or tested by Prisma, but we've been using it at Spacedrive and it's worked pretty well.

Query batching

PrismaClient::_batch is now available for running a sequence of queries inside a transaction! It's fully type-safe and works with tuples and iterators, as explained here

rspc integration

Enabling the rspc feature for both prisma-client-rust and prisma-client-rust-cli makes it possible for the rspc router to generate TypeScript bindings to your Prisma types by simply returning the result of a query inside a resolver. Errors can also be handled, and it's all explained here.

Some other changes

Case sensitivity support (#125)

Different filters that apply to the same field are now merged properly, so case sensitive comparisons should now work.

Running the CLI with no parameters displays help (#139)

An internal use warning is no longer printed when running the CLI with no arguments, instead the CLI's help menu is printed.

Prisma v4.2.0

While Prisma v4.3.0 just got released, I wanted to get this release out ASAP so 4.3.0 features may be supported sometime in the future.

Generator refactoring

In an effort to make the generator of the CLI more approachable, significant refactoring has been done to make it more modular and understandable.

90% reduction in Prisma engine repo size

Turns out that previously, cloning Brendonovich/prisma-engines would clone every branch in the repo, resulting in a 400mb download. After deleting every branch except main I screwed something up resulting in 0.5.3 needing to be released, but now downloading the engines is only a 40mb endeavour!

Discord server!

It's been requested in the past and I felt that Discussions would be adequate, but now I would rather help and discussion be done in Discord - it's much easier to interact one-on-one and ask questions about feature ideas that way.
However, I don't feel that Prisma Client Rust is a big enough project to warrant having its own server, so it will share one with rspc. The two projects pair together extremely well, I expect many of you using Prisma Client Rust will use rspc, and the developer of rspc is a friend and coworker. We are both very familiar with each other's technologies and can be more helpful in one place.

Prisma sponsorship!

To my amazement, Prisma chose Prisma Client Rust as the July recipient of their FOSS fund! This money is greatly appreciated and will aid future development of Prisma Client Rust.

Going Forward

There's plenty more that can be added to Prisma Client Rust, but I hope that 0.6.0 will offer enough features that more updates can wait for some time, and that community members can start contributing rather than me implementing things.
Optimisation is something I'd like to pay extra attention to - only including required databas...

Read more

0.5.3

24 Aug 13:50
Compare
Choose a tag to compare

This release fixes a recently introduced issue (sorry, my bad!) regarding version resolution of the Prisma engines. It seems that in preparing for 0.6.0 I broke 0.5.2 🙃.

I'm aiming to release 0.6.0 by the end of the month. With it will be many new features, some bug fixes, and Prisma v4.2.0.

0.5.2

19 Jun 23:35
Compare
Choose a tag to compare

Prisma Client Rust is here with some important bug fixes, extra features, and preparation for 0.6.0.

Bytes type now supported

Interacting with a field that had the Bytes type would result in an error. This is because Prisma was taking the Vec<u8> of data and base64 encoding it into a string, but Prisma Client Rust expected a Vec<u8>, leading to a deserialisation error. This is no longer the case, as I have made a clone of the PrismaValue enum that does not base64 encode bytes when serialised.

Scalar array cursors now expect Vec (#80)

Some simple errors in the codegen were resulting in cursor variants of scalar arrays not expecting Vecs.

Optional relations can be unlinked, and required relations cannot (#81)

A simple negation error was leading to link/unlink being generated on the wrong fields.

Action creators now consume self

Calling create, find_unique etc. now consumes the Actions instance that is created when calling a client's model accessor. This means that doing let query = client.model().create(); no longer produces an error, since the Create struct doesn't reference the Actions struct it was created from.

Upsert always passes create and update arguments to Prisma engines

Calling upsert will now always provide the Prisma engines with arguments for create and update, even if an empty array is provided. This is required according to the engines GraphQL schema.

Most parameters implement Clone

This is more of a change for myself than anything.

Moved most CLI logic into separate sdk crate

While not ready for public use yet, the sdk crate will be the new home of much of the generator logic in order to make building custom generators much easier. I am doing this now as we are using it at Spacedrive, but it is not ready to be used publicly. It will change.

0.5.1

06 Jun 09:26
Compare
Choose a tag to compare

Prisma Client Rust 0.5.1 is here with some minor bugfixes!

@id and @unique do not duplicate UniqueWhereParam

#71 has been fixed, so annotating a field with @id and @unique together will not result in two variants being generated inside a model's UniqueWhereParam enum.

Compound IDs generate UniqueWhereParam variants

#69 detailed a regression in which compound IDs do not generate a corresponding UniqueWhereParam variant. This was a result of using more of Prisma's internal schema types, in which primary keys are stored separately to unique fields, and as such unique variants were not being generated for compound IDs.

0.5.0

26 May 04:14
Compare
Choose a tag to compare

It's been a while and some big changes have been made, but Prisma Client Rust 0.5.0 is here! Improvements include major internal optimisations, Arm64 and Prisma 3.13.0 support, many bugfixes and more!

Arm Support

Prisma CLI binaries have been published for Arm platforms, and now Prisma Client Rust can download different CLI binaries depending on your CPU architecture. These binaries seem to be stable, but have not been extensively tested, so please report any issues you find.

Optimisations

Codegen now relies heavily on Prisma's internal datataypes, resulting in more accurate and reliable generated code. The generated client also uses PrismaValues extensively, providing a more accurate interface with the Prisma engines.

Error Handling

Prisma errors can be annoying to handle, so documentation and the function error_is_type have been added to improve the experience of determining whether an error is of a particular type.

Rust Naming Overlaps

By checking against the list of Rust's reserved keywords, the CLI will now let you know if any of your model or field names match any reserved keywords, instead of simply failing to compile after generating the client.

Separation of Client Internals

PrismaClient, internal enums and more are now generated inside the _prisma module, rather than at the root of the client. This ensures that enums, which are generated at the root, never have naming collisions with internal types.

More Accurate Upsert Parameters

upsert now takes 3 parameter: A unique filter, the create args, and update args all in one, as opposed to create and update having to be called separately. This has been done in order to be more type-safe, since not calling create or update previously would have resulted in an error from Prisma.

Fixes

  • PrismaClient now implements Debug by simply outputting "PrismaClient"
  • Removed print and dbg calls
  • Enums are treated differently to scalar types, and generate properly now
  • Having multiple relations of the same type is now supported, since each relation gets dedicated structs for converting to WithParams

What's next?

I have recently joined the team at Spacedrive and will be focusing most of my work on Prisma Client Rust towards features that are required there, but will also try and do extra during my time off. I endeavour to complete #60 and #24 for 0.5.1/0.6, but not much more than that for now. I will, however, be working on improving the experience of creating custom generators, as these will be required at Spacedrive, and my friend @oscartbeaumont is developing a GraphQL library that will use a custom Prisma generator for an incredible Rust, Prisma and GraphQL experience.

Thankyou to everyone who has starred, shared and opened issues on this project. It's been a blast working on a library that people are excited about, and I look forward to seeing Prisma become more widely used in the Rust community!

0.4.1

28 Apr 00:50
Compare
Choose a tag to compare

In the pursuit of closing #45, I also ended up closing #22. So here's a minor update with some major features and performance boosts!

It would be greatly appreciated if you starred and shared this repo!

Nested Queries

fetch now has all the same methods on it as find_many and find_unique, meaning you can fetch relations to an infinite depth, and even paginate relations at the same time!

Direct AST to GraphQL Conversion

The re-implementation of the query AST has made it possible to convert directly from enums and structs to GraphQL structures, bypassing an entire step before execution where a GraphQL string was constructed and then parsed.

Axum GraphQL Example

Thanks to @aaronleopold for creating an example of using Prisma Client Rust with async-graphql and axum!

0.4.0

19 Apr 16:33
Compare
Choose a tag to compare

After much work, I'm excited to release version 0.4.0 of Prisma Client Rust! 🎉

This release is much more refined than the initial versions, with many bugs fixed, many approaches rethought, and a whole load of breaking changes 🙃 (trust me, it's for the best). All the information you should need is available in the docs, and if you have a question then feel free to ask!

It would be hugely appreciated if you starred and shared this repo!

Major Changes

CLI is no longer distributed as an installable binary

To allow tying the CLI version to the specific project it is being used in, the CLI is now available as a library and can be used to create a custom executable within your project. Additionally, none of Prisma Client Rust's code will be distributed on crates.io going forward, as 1. There are plans to use Prisma engine code in the CLI and 2. it's more consistent.

Models and fields are now modules

All the functions, structs and enums related to models and fields are now inside their own modules. This was done to standardised naming within the code generation and have consistency between model and field accessor naming (since models used to be PascalCase while fields were snake_case).

Update and upsert

update and upsert queries are now supported.

Queries return Result values

An awaited query will return a Result, with the error type being a prisma_client_rust::query::Error

New Features

Way more filters

Many filters are now discovered through the Prisma engines, so more expressive queries can now be made.

Pagination

take, skip, cursor and order_by filters are all available too!

Unique fields are enforced

Separate types now exist for unique fields, narrowing the values that can be used in find_unique queries.

Compund unique fields

Equality comparisons of compound unique fields can be constructed with ease.

Fixes

Linux support

Previously, engine binaries did not download properly on Linux. This is fixed now thanks to collaboration with @oscartbeaumont.

Correct handling of optional single relations

Optional single relations are now stored as Option<Option<Data>> on data structs, and thus whether they have been fetched or not can be reported as an error.

0.3.1

07 Apr 15:13
Compare
Choose a tag to compare
0.3.1 Pre-release
Pre-release

Changes

  • Prisma's query engines are now referenced from my fork, which locks all git dependencies to using specific tags/commits, rather than always using latest. Fixes #25

0.3.0

02 Mar 18:27
Compare
Choose a tag to compare
0.3.0 Pre-release
Pre-release

Important

As detailed below, the method for installing both the CLI and the library have changed, so it is recommended that you check the updated README for instructions on how to properly install them both.

Changes

  • Client now links directly to prisma engines, improving performance and removing the need to download engine binaries and run a localhost server.
  • As a result of linking to the prisma engines, the library cannot be published to crates.io, only the CLI can as a separate package. Thus, instructions and warnings have been updated accordingly in the README.
  • Prisma CLI has been updated to version 3.10.0.
  • Single depth relations can be fetched using the with() and fetch() functions.
  • Model codegen has been unified into one file with many structs, improving readability and maintainability.