mattn / Go Nulltype
Null friendly types
Stars: ✭ 79
Projects that are alternatives of or similar to Go Nulltype
Sirdb
👨 a simple, git diffable JSON database on yer filesystem. By the power of NodeJS
Stars: ✭ 508 (+543.04%)
Mutual labels: json, database
Pickledb
pickleDB is an open source key-value store using Python's json module.
Stars: ✭ 549 (+594.94%)
Mutual labels: json, database
Comuni Json
🇮🇹 Database JSON comuni italiani (2020) con informazioni ISTAT + CAP
Stars: ✭ 416 (+426.58%)
Mutual labels: json, database
Tinydb
TinyDB is a lightweight document oriented database optimized for your happiness :)
Stars: ✭ 4,713 (+5865.82%)
Mutual labels: json, database
Filemasta
A search application to explore, discover and share online files
Stars: ✭ 571 (+622.78%)
Mutual labels: json, database
Jsonlite
A simple, self-contained, serverless, zero-configuration, json document store.
Stars: ✭ 819 (+936.71%)
Mutual labels: json, database
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+807.59%)
Mutual labels: json, database
Stormdb
🌩️ StormDB is a tiny, lightweight, 0 dependency, easy-to-use JSON-based database for NodeJS, the browser or Electron.
Stars: ✭ 406 (+413.92%)
Mutual labels: json, database
Bigchaindb
Meet BigchainDB. The blockchain database.
Stars: ✭ 3,768 (+4669.62%)
Mutual labels: json, database
Sleekdb
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Stars: ✭ 450 (+469.62%)
Mutual labels: json, database
Anime Offline Database
Updated every week: A JSON based offline anime database containing the most important meta data as well as cross references to various anime sites such as MAL, ANIDB, ANILIST, KITSU and more...
Stars: ✭ 292 (+269.62%)
Mutual labels: json, database
Node Json Db
A simple "database" that use JSON file for Node.JS.
Stars: ✭ 314 (+297.47%)
Mutual labels: json, database
Sheetjs
📗 SheetJS Community Edition -- Spreadsheet Data Toolkit
Stars: ✭ 28,479 (+35949.37%)
Mutual labels: json, database
Java Client Api
Java client for the MarkLogic enterprise NoSQL database
Stars: ✭ 52 (-34.18%)
Mutual labels: json, database
go-nulltype
Nullable types friendly to json.Encoder, json.Decoder, database/sql, fmt.Stringer, text/template, html/template, some of ORMs.
Supported types:
- NullBool
- NullString
- NullFloat64
- NullInt64
- NullTime
Usage
import "github.com/mattn/go-nulltype"
type User struct {
Name nulltype.NullString `json:"name"`
}
friendly to Stringer
var user User
fmt.Println(user.Name.Valid()) // false
fmt.Println(user.Name) // ""
user.Name.Set("Bob")
fmt.Println(user.Name.Valid()) // true
fmt.Println(user.Name) // "Bob"
fmt.Println(user.Name.StringValue() == "Bob") // true
user.Name.Reset()
fmt.Println(user.Name.Valid()) // false
fmt.Println(user.Name) // ""
friendly to json.MarshalJSON
var user User
fmt.Println(user.Name.Valid()) // false
json.NewEncoder(os.Stdout).Encode(user) // {"name": null}
user.Name.Set("Bob")
fmt.Println(user.Name.Valid()) // true
json.NewEncoder(os.Stdout).Encode(user) // {"name": "Bob"}
friendly to json.UnmarshalJSON
var user User
s := `{"name": "Bob"}`
json.NewDecoder(strings.NewReader(s)).Decode(&user)
fmt.Println(user.Name.Valid()) // true
fmt.Println(user.Name) // "Bob"
s = `{"name": null}`
json.NewDecoder(strings.NewReader(s)).Decode(&user)
fmt.Println(user.Name.Valid()) // false
fmt.Println(user.Name) // ""
friendly to database/sql
var user User
db.QueryRow(`SELECT name FROM users`).Scan(&user.Name)
fmt.Println(user.Name.Valid()) // true or false
fmt.Println(user.Name) // "Bob" or ""
db.Exec(`INSERT INTO users(name) VALUES($1)`, user.Name)
friendly to ORM
Struct tag with gorp.
type Post struct {
Id int64 `db:"post_id"`
Created int64
Title string `db:",size:50"`
Body nulltype.NullString `db:"body,size:1024"`
}
p := Post{
Created: time.Now().UnixNano(),
Title: title,
Body: nulltype.NullStringOf(body),
}
err = dbmap.Insert(&p)
Installation
go get github.com/mattn/go-nulltype
License
MIT
Author
Yasuhiro Matsumoto
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].