std

package
v0.0.0-...-51ce559 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToFloat64

func BoolToFloat64(b bool) float64

BoolToFloat converts b to float the same way like PHP do.

func BoolToInt

func BoolToInt(b bool) int

BoolToInt converts b to int the same way like PHP do.

func Concat

func Concat(left, right interface{}) string

Concat joins two values, interfaces, to one string. Represents PHP's "." concat operator.

func FileExists

func FileExists(f string) bool

FileExists checks if the file with the given name exists. It does the same thing as PHP file_exists.

func Microtime

func Microtime() float64

Microtime returns current Unix timestamp with microseconds. It represents PHP function with the same name, with one big difference, this value is always float.

See php.net/manual/en/function.microtime.php for more details.

func Scandir

func Scandir(d string) array.String

Scandir returns every file and folder found in the directory. If d is not valid directory, empty array is returned. It does the same thing as PHP scandir, here it is just wrapper to "hide" extra information, only name is required. Right now it does not return "." and "..", but these directories does not make much sense anyways.

func StrDec

func StrDec(s string) string

StrDec behaves the same way as PHP string--. TODO: Implement this.

func StrInc

func StrInc(s string) string

StrInc behaves the same way as PHP string++. TODO: Implement this.

func ToInt

func ToInt(s interface{}) int

ToInt transfers anything to int. The main part is conversion from string to int. It does the same thing as (int) in PHP, that means it tries to parse it as long it looks like an int. BUG(ls): it does not support diferent bases like HEX etc.

func Truthy

func Truthy(i interface{}) bool

Truthy converts anything to boolean. Used to simulate implicit conversion.

Types

type Bool

type Bool interface {
	// ToBool is the only method implemented
	// in this interface. The name is specific
	// enough so no collisions should be ever
	// discovered.
	ToBool() bool
}

Bool is used to add an option to implement non-implicit conversion. Used in std.Array and std.SQL.

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

Rows wraps *sqlx.Rows, the main goal is to rename a method to make it more clear what it does, and hide SQL package in the transpiled script.

func (*Rows) Next

func (r *Rows) Next() bool

Next is one of the methods use to implement mysqli_fetch_array(). Instead of returning struct or a false, which represents if the result is empty, Next is used only for this flag "is empty".

func (*Rows) Scan

func (r *Rows) Scan(t interface{})

Scan fills passed pointer to struct t with values found in the rows. It is the second implementation of mysqli_fetch_array(). In PHP it has two arguments, first one is here represented by Rows, the second one defines returned value type. Here I support only MYSQLI_ASSOC, which is here implemented as struct. This is probably the only way how to make strictly typed with the current set of supported operations in the transpiler.

type SQL

type SQL struct {
	// contains filtered or unexported fields
}

SQL wraps MySQL connection. The main purpose is to behave the same way as PHP SQL connection does.

func NewSQL

func NewSQL(server, user, password string) *SQL

NewSQL creates struct SQL with defined server, user, and its password. Function call is the same like mysqli_connect().

func (*SQL) Close

func (s *SQL) Close()

Close is another wrapper for connection, but this one is not present in PHP. Closes SQL connection.

func (*SQL) Query

func (s *SQL) Query(q string) *Rows

Query performs SQL query defined in q. It returns std.Rows. It is the alias for mysqli_query(), where connection is the struct, not the first argument.

func (*SQL) SelectDB

func (s *SQL) SelectDB(table string)

SelectDB adds information about table. With this information the connection is really opened. It is opened as "Unsafe" connection. This hides issues with not reading every column in `SELECT *` etc. It is the alias for mysqli_select_db(), where connection is the struct, not the first argument.

func (SQL) ToBool

func (s SQL) ToBool() bool

ToBool implements inteface Bool, the simplest way how to check if the connection is valid.

Notes

Bugs

  • it does not support diferent bases like HEX etc.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL