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

[orm] pass generic types #24041

Open
koplenov opened this issue Mar 25, 2025 · 3 comments
Open

[orm] pass generic types #24041

koplenov opened this issue Mar 25, 2025 · 3 comments

Comments

@koplenov
Copy link
Contributor

koplenov commented Mar 25, 2025

V version: V 0.4.9 1d9aa88, press to see full `v doctor` output
V full version V 0.4.9 1d9aa88
OS windows, Њ ©Єа®б®дв Windows 10 Pro 19045 64-а §ап¤­ п
Processor 28 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz
Memory 20.92GB/31.86GB
V executable C:\dev\v\v.exe
V last modified time 2025-01-26 10:35:18
V home dir OK, value: C:\dev\v
VMODULES OK, value: C:\Users\koplenov.vmodules
VTMP OK, value: C:\Users\koplenov\AppData\Local\Temp\v_0
Current working dir OK, value: C:\dev\mam_prod\v\litequeue\litequeue\orm_gen
Git version git version 2.39.1.windows.1
V git status Error: fatal: not a git repository (or any of the parent directories): .git
.git/config present false
cc version N/A
gcc version N/A
clang version N/A
msvc version N/A
tcc version tcc version 0.9.27 (x86_64 Windows)
tcc git status N/A
emcc version N/A
glibc version N/A

What did you do?
./v -g -o vdbg cmd/v && ./vdbg .\main.v && C:\dev\mam_prod\v\litequeue\litequeue\orm_gen\main.exe

module main

import db.sqlite

struct Test {
	some_string string
	some_int 	int
}

fn main() {
	db := sqlite.connect("test.db")
	or { panic('Failed to connect to database: ${err}') }

	crete_generick_table[Test](db)
}

fn crete_generick_table[T] (db sqlite.DB) {
	sql db {
		create table T
	} or { panic('Failed to create table: ${err}') }
}

What did you see?

main.v:20:2: error: ORM: the table symbol `T` has to be a struct
   18 |     sql db {
   19 |         create table T
   20 |     } or { panic('Failed to create table: ${err}') }
      |     ^
   21 | }

What did you expect to see?

Must compile and works

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Copy link

Connected to Huly®: V_0.6-22433

@koplenov
Copy link
Contributor Author

I think this code should work

module main

import db.sqlite

pub struct Message[T] {
	id       int
	T
}

// usage
struct Payload {
	some_filed_1 string
	some_filed_2 int
}

fn test_handler(message Message[Payload]) ! {
	return error('AAAA')
}

fn main() {
	db_path := 'test_queue.db'
	mut conn := sqlite.connect(db_path) or { panic('Failed to connect to database: ${err}') }

	sql conn {
		create table Message[Payload]
	}!
}

But I get this error:

PS C:\dev\mam_prod\v\litequeue\litequeue2> v run .
queue.v:8:1: error: expecting type declaration
    6 |     id       int
    7 |     T
    8 | }
      | ^
    9 |
   10 | // usage

@koplenov
Copy link
Contributor Author

this code compiled

module main

import db.sqlite

pub struct Message {
	Payload
	id       int
}

// usage
struct Payload {
	some_filed_1 string
	some_filed_2 int
}

fn test_handler(message Message) ! {
	return error('AAAA')
}

fn main() {
	db_path := 'test_queue.db'
	mut conn := sqlite.connect(db_path) or { panic('Failed to connect to database: ${err}') }

	sql conn {
		create table Message
	}!
}

but at run i get this error:

V panic: result not set (Unknown type 0)
v hash: 1d9aa88
C:/Users/koplenov/AppData/Local/Temp/v_0/litequeue2.01JQ7Q2M4RRXVKNZVPG0HR9JBT.tmp.c:5633: at _v_panic: Backtrace
C:/Users/koplenov/AppData/Local/Temp/v_0/litequeue2.01JQ7Q2M4RRXVKNZVPG0HR9JBT.tmp.c:5599: by panic_result_not_set
C:/Users/koplenov/AppData/Local/Temp/v_0/litequeue2.01JQ7Q2M4RRXVKNZVPG0HR9JBT.tmp.c:10298: by main__main
C:/Users/koplenov/AppData/Local/Temp/v_0/litequeue2.01JQ7Q2M4RRXVKNZVPG0HR9JBT.tmp.c:10375: by wmain
00587578 : by ???
005876db : by ???    
7ffd591f7374 : by ???

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

1 participant