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

support for V ORM #198

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

daniel-le97
Copy link

Now that V ORM allows mutable Connections via vlang/v#22684,
integration of the ORM does not require major workarounds or creating separate DB connections

Example usage

module main

import vsql

struct Product {
	id           int
	product_name string
	price        f64
}

fn main() {
	mut db := vsql.open('test.vsql')!

	sql db {
		create table Product
	}!
}

Tests

Tests can be run by either of the following

v -stats test ./vsql/orm_test.v

or

make orm-test

This implementation does take code/ideas from the initial work done on this in #102

It also implements most of the same test done in the original work.

The only change i see is that in this implementation, @[primary] attributes are also not supported as they will break delete queries. This can easily be changed tho.

Not Supported

  • enums for field values
  • default attribute
  • unique attribute
  • primary attribute

fixes #90

@@ -87,6 +87,9 @@ btree-test: oldv
sql-test: oldv
$(V) -stats $(BUILD_OPTIONS) vsql/sql_test.v

orm-test: oldv
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just adding a note here for me to add this to the docs.

vsql/orm.v Outdated Show resolved Hide resolved
vsql/orm.v Outdated Show resolved Hide resolved
vsql/orm.v Outdated Show resolved Hide resolved
vsql/orm.v Outdated Show resolved Hide resolved
vsql/orm.v Outdated Show resolved Hide resolved
vsql/orm.v Outdated Show resolved Hide resolved
vsql/orm_test.v Show resolved Hide resolved
@daniel-le97
Copy link
Author

Sorry for not cleaning this up, i have now removed comments/ commented code that do not add context

@elliotchance
Copy link
Owner

I fixed the docs CI job and ran v fmt in #201, so please rebase.

Also, can you add a section to https://github.com/elliotchance/vsql/blob/main/docs/testing.rst#test-suites to add orm-test as its own suite.

example() or { panic(err) }
}

// NOTE for some reason if we declare a @[primary] on a struct field, we can not do delete queries on the tables...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now fixed: #203

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

Successfully merging this pull request may close these issues.

Support for builtin orm
2 participants