-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vlang:master' into encoding.iconv
- Loading branch information
Showing
39 changed files
with
906 additions
and
126 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module main | ||
|
||
import db.sqlite | ||
|
||
@[table: 'blog'] | ||
pub struct Blog { | ||
id int @[primary; sql: serial] | ||
slug string | ||
language string | ||
} | ||
|
||
fn records_by_field[T](db sqlite.DB, fieldname string, value string) ![]T { | ||
$for field in T.fields { | ||
if field.name == fieldname { | ||
entries := sql db { | ||
select from Blog where field.name == value | ||
} or { return err } | ||
return entries | ||
} | ||
} | ||
return error('fieldname not found') | ||
} | ||
|
||
fn test_main() { | ||
db := sqlite.connect(':memory:')! | ||
sql db { | ||
create table Blog | ||
}! | ||
|
||
row := Blog{ | ||
slug: 'Test' | ||
language: 'v' | ||
} | ||
|
||
sql db { | ||
insert row into Blog | ||
}! | ||
rows := records_by_field[Blog](db, 'language', 'v') or { | ||
println(err) | ||
return | ||
} | ||
assert rows.len == 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import encoding.csv | ||
|
||
fn test_no_ending() { | ||
data := 'x,y,d | ||
a,b | ||
w' | ||
mut parser := csv.new_reader(data) | ||
mut arr := []string{} | ||
for { | ||
items := parser.read() or { break } | ||
arr << items.join('-') | ||
} | ||
dump(arr) | ||
assert arr[0].str() == 'x-y-d' | ||
assert arr[1].str() == 'a-b' | ||
assert arr[2].str() == 'w' | ||
} | ||
|
||
fn test_with_ending() { | ||
data := 'x,y,d | ||
a,b | ||
w | ||
' | ||
mut parser := csv.new_reader(data) | ||
mut arr := []string{} | ||
for { | ||
items := parser.read() or { break } | ||
arr << items.join('-') | ||
} | ||
dump(arr) | ||
assert arr[0].str() == 'x-y-d' | ||
assert arr[1].str() == 'a-b' | ||
assert arr[2].str() == 'w' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Module { | ||
name: 'semver' | ||
version: '0.4.7' | ||
version: '0.4.8' | ||
deps: [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.