Skip to content

Commit

Permalink
v: Update for V 0.4.3 ed754cf (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Dec 21, 2023
1 parent 8036600 commit 6514f2c
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 149 deletions.
146 changes: 45 additions & 101 deletions docs/v-client-library-docs.rst

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion generate-grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def var_name(name):
grammar_file.write('\t' + var_name(gr) + '.productions << &EarleyProduction{[\n')
for term in production.terms:
if isinstance(term, str):
grammar_file.write("\t\t&EarleyRuleOrString{str: '" + rule_name(term) + "', rule: 0},\n")
grammar_file.write("\t\t&EarleyRuleOrString{str: '" + rule_name(term) + "', rule: unsafe { 0 }},\n")
else:
grammar_file.write("\t\t&EarleyRuleOrString{rule: " + var_name(term) + "},\n")
grammar_file.write('\t]}\n')
Expand Down
10 changes: 5 additions & 5 deletions vsql/compiler.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module vsql

struct Compiler {
tables map[string]Table
params map[string]Value [required]
params map[string]Value @[required]
mut:
conn &Connection [required]
conn &Connection @[required]
// context is used to describe the indetifier environment. For example, in an
// UPDATE statement we know the table we're operating on and so any
// identifiers have to be reoslved against that instead of just searching all
Expand All @@ -17,9 +17,9 @@ mut:
type CompiledFn = fn (mut conn Connection, data Row, params map[string]Value) !Value

struct CompileResult {
run CompiledFn [required]
typ Type [required]
contains_agg bool [required]
run CompiledFn @[required]
typ Type @[required]
contains_agg bool @[required]
}

fn (c CompileResult) with_agg(contains_agg bool) CompileResult {
Expand Down
6 changes: 3 additions & 3 deletions vsql/connection.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const default_schema_name = 'PUBLIC'

// A Connection allows querying and other introspection for a database file. Use
// open() or open_database() to create a Connection.
[heap]
@[heap]
pub struct CatalogConnection {
// path is the file name of the database. It can be the special name
// ':memory:'.
Expand All @@ -28,7 +28,7 @@ mut:

// A Connection allows querying and other introspection for a database file. Use
// open() or open_database() to create a Connection.
[heap]
@[heap]
pub struct Connection {
mut:
catalogs map[string]&CatalogConnection
Expand All @@ -51,7 +51,7 @@ pub mut:
// now allows you to override the wall clock that is used. The Time must be
// in UTC with a separate offset for the current local timezone (in positive
// or negative minutes).
now fn () (time.Time, i16) [required]
now fn () (time.Time, i16) @[required]
// warnings are SQLSTATE errors that do not stop the execution. For example,
// if a value must be truncated during a runtime CAST.
//
Expand Down
18 changes: 9 additions & 9 deletions vsql/earley.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module vsql

import strings

[heap]
@[heap]
struct EarleyRuleOrString {
rule &EarleyRule
str string
Expand All @@ -19,7 +19,7 @@ fn (o &EarleyRuleOrString) str() string {
return o.str
}

[heap]
@[heap]
struct EarleyProduction {
terms []&EarleyRuleOrString
}
Expand All @@ -32,7 +32,7 @@ fn (prod &EarleyProduction) index() string {
return elems.join(',')
}

[heap]
@[heap]
struct EarleyRule {
name string
mut:
Expand All @@ -43,7 +43,7 @@ fn (rule &EarleyRule) str() string {
return rule.name
}

[heap]
@[heap]
struct EarleyState {
name string
production &EarleyProduction
Expand All @@ -68,7 +68,7 @@ fn new_earley_state(name string, production &EarleyProduction, dot_index int, st
start_column: start_column
dot_index: dot_index
rules: rules
end_column: 0
end_column: unsafe { 0 }
}
}

Expand Down Expand Up @@ -99,14 +99,14 @@ fn (state &EarleyState) completed() bool {
fn (state &EarleyState) next_term() &EarleyRuleOrString {
if state.completed() {
return &EarleyRuleOrString{
rule: 0
rule: unsafe { 0 }
}
}

return state.production.terms[state.dot_index]
}

[heap]
@[heap]
struct Set {
mut:
elems map[string]bool
Expand All @@ -124,7 +124,7 @@ fn (mut s Set) add(v string) {
s.elems[v] = true
}

[heap]
@[heap]
struct EarleyColumn {
index int
token string
Expand Down Expand Up @@ -172,7 +172,7 @@ fn (col &EarleyColumn) print() {
println('')
}

[heap]
@[heap]
struct EarleyNode {
value &EarleyState
children []&EarleyNode
Expand Down
2 changes: 1 addition & 1 deletion vsql/funcs.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct Func {
name string
arg_types []Type
is_agg bool
func fn ([]Value) !Value [required]
func fn ([]Value) !Value @[required]
return_type Type
}

Expand Down
2 changes: 1 addition & 1 deletion vsql/lexer.v
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn tokenize(sql_stmt string) []Token {
return tokens
}

[inline]
@[inline]
fn is_identifier_char(c u8, is_not_first bool) bool {
yes := (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || c == `_`

Expand Down
7 changes: 3 additions & 4 deletions vsql/page.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ module vsql
// not the required int is kind of fiddly). Also, there's almost no case where
// we need to deal with all cases because they are context specific. So let's
// just keep these as u8 for now.
const (
kind_leaf = 0 // page contains only objects.
kind_not_leaf = 1 // page contains only links to other pages.
)
const kind_leaf = 0 // page contains only objects.

const kind_not_leaf = 1 // page contains only links to other pages.

// page_object_prefix_length is the precalculated length that will be the
// combination of all fixed width meta for the page object.
Expand Down
2 changes: 1 addition & 1 deletion vsql/query_cache.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module vsql
// statements. By default, a new QueryCache is created for each Connection.
// However, you can share a single QueryCache safely amung multiple connections
// for even better performance. See ConnectionOptions.
[heap]
@[heap]
pub struct QueryCache {
mut:
stmts map[string]Stmt
Expand Down
2 changes: 1 addition & 1 deletion vsql/std_query_expression.v
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn (mut o OrderOperation) execute(rows []Row) ![]Row {
return head.rows()
}

[heap]
@[heap]
struct RowLink {
row Row
mut:
Expand Down
36 changes: 15 additions & 21 deletions vsql/time.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ module vsql
import regex
import time

const (
second_period = i64(1000000)
minute_period = 60 * second_period
hour_period = 60 * minute_period
day_period = 24 * hour_period
month_period = 31 * day_period
year_period = 12 * month_period
)
const second_period = i64(1000000)
const minute_period = 60 * second_period
const hour_period = 60 * minute_period
const day_period = 24 * hour_period
const month_period = 31 * day_period
const year_period = 12 * month_period

// When a precision is not specified by TIME or TIMESTAMP types we should use
// these defaults. These are layed out specifically in the SQL standard.
const (
default_time_precision = 0
default_timestamp_precision = 6
)
const default_time_precision = 0
const default_timestamp_precision = 6

// The SQL standard is pretty strict about the format for date and time
// literals. They express this through the grammar itself, but for simplicity
Expand All @@ -43,15 +39,13 @@ const (
// <time zone interval> ::=
// <sign> <hours value> <colon> <minutes value>
//
const (
unquoted_date_string = r'\d+\-\d+\-\d+'
unquoted_time_string_with_time_zone = r'\d+:\d+:\d+(\.\d{1,6})?[-+]\d+:\d+'
unquoted_time_string_without_time_zone = r'\d+:\d+:\d+(\.\d{1,6})?'
unquoted_timestamp_with_time_zone_string = '^' + unquoted_date_string + r'\s' +
unquoted_time_string_with_time_zone + '$'
unquoted_timestamp_without_time_zone_string = '^' + unquoted_date_string + r'\s' +
unquoted_time_string_without_time_zone + '$'
)
const unquoted_date_string = r'\d+\-\d+\-\d+'
const unquoted_time_string_with_time_zone = r'\d+:\d+:\d+(\.\d{1,6})?[-+]\d+:\d+'
const unquoted_time_string_without_time_zone = r'\d+:\d+:\d+(\.\d{1,6})?'
const unquoted_timestamp_with_time_zone_string = '^' + unquoted_date_string + r'\s' +
unquoted_time_string_with_time_zone + '$'
const unquoted_timestamp_without_time_zone_string = '^' + unquoted_date_string + r'\s' +
unquoted_time_string_without_time_zone + '$'

// Time is the internal way that time is represented and provides other
// conversions such as to/from storage and to/from V's native time.Time.
Expand Down
2 changes: 1 addition & 1 deletion vsql/virtual_table.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type VirtualTableProviderFn = fn (mut t VirtualTable) !
pub struct VirtualTable {
create_table_sql string
create_table_stmt TableDefinition
data VirtualTableProviderFn [required]
data VirtualTableProviderFn @[required]
mut:
is_done bool
rows []Row
Expand Down

0 comments on commit 6514f2c

Please sign in to comment.